2010-09-25 72 views
1

我得到100%的泄漏。我不知道如何在返回對象後釋放對象 您可以解釋一下如何釋放已分配標題對象的過程。我在下面的代碼泄漏

-(Titles *)listTiles 
{ 
Tiles* tile = [[Tiles alloc] init]; 
tile.googleTile_X = (int)tileX; 
tile.googleTile_Y = (int) pow(2, aZoom) - 1- tileY ; 
tile.zoomLevel = aZoom; 
return tile; 
} 

回答

1

一般來說,這取決於,但在這種特殊情況下,我相信你可以使用return [tile autorelease]

P.S .:請正確格式化您的代碼。

2

你發送-alloc,,未能發送-release-autorelease到你所創建的對象。

閱讀Apple關於內存管理的介紹性文檔。

1
-(Titles *)listTiles 
{ 
    Tiles* tile = [[[Tiles alloc] init] autorelease]; 
    tile.googleTile_X = (int)tileX; 
    tile.googleTile_Y = (int) pow(2, aZoom) - 1- tileY ; 
    tile.zoomLevel = aZoom; 
    return tile; 
}