2012-06-04 46 views
1

我是iPhone開發新手。 我在view.also上顯示了很多圖像,並且我將更多圖像命名爲LOAD MORE按鈕。我也正在LOAD MORE事件中下載圖像。 這裏是我的代碼:`接收內存泄漏

-(void)btnLoadMorePressed 
{ 
    [appdelegate showLoader:MBProgressHUDModeIndeterminate]; 

    RequestResponseManager *requestManager=[RequestResponseManager sharedInstance]; 
    [requestManager setRequestPropery:self ExtraInfo:nil]; 

    Album *album=[appdelegate.CurrentUser.albumListarray objectAtIndex:indexNum-1]; 

    NSArray *obj_keys = [NSArray arrayWithObjects:@"UserId",@"AlbumId",@"SessionId",@"PageNo",@"ModMethod", nil]; 
    NSArray *objects = [NSArray arrayWithObjects:appdelegate.CurrentUser.userId,album.AlbumId,appdelegate.sessionId,[NSString stringWithFormat:@"%d",currentPage],@"getPhotoListByAlbumId",nil]; 
    NSDictionary *jsonDictionary = [NSDictionary dictionaryWithObjects:objects forKeys:obj_keys]; 
    NSString *jsonString = [jsonDictionary JSONRepresentation]; 
    NSString *requestString=[NSString stringWithFormat:@"data=%@",jsonString]; 

    currentRequest=JGetAlbumPhotoList; 
    [requestManager sendPostHttpRequest:GET_USER_ALBUM_PHOTO_URL RequestType:JGetAlbumPhotoList PostContent:requestString]; 
} 

,但是當我試圖獲取更多的圖像,它給了我記憶警告,然後突然crashing.please幫助me.thanking你......

+0

您需要詳細說明發生了什麼。什麼錯誤消息,你有什麼堆棧跟蹤和日誌記錄? –

+0

這是我的圖像下載代碼: - (void)StartImageDownload { ImageDownload = 0; (int i = 0; i <[appdelegate.CurrentUser.albumImageArray count]; i ++) {0121} if(!aPhoto.Image) [self startIconDownload:aPhoto.ImageName forIndexPath:[NSNumber numberWithInt:i]]; else { ImageDownload ++; } } } – HML

+0

- (無效)startIconDownload:(的NSString *)用戶forIndexPath:(的NSNumber *)指數 { 如果([用戶長度] == 0) 回報; IconDownloader * iconDownloader = [imageDownloadsInProgress objectForKey:index]; (iconDownloader ==零) iconDownloader = [[IconDownloader alloc] init]; iconDownloader.imageKey = index; iconDownloader.imgURL = user; iconDownloader.appRecord = self; [imageDownloadsInProgress setObject:iconDownloader forKey:index]; [iconDownloader startDownload]; [iconDownloader發佈]; } } – HML

回答

0

釋放所有對象您已使用dealloc方法創建並將所有對象設置爲null。

防爆:

- (void)dealloc { 

    [super dealloc]; 

    [image1 release]; 
    image1=nil; 

} 
+0

但它在dealloc調用之前崩潰... – HML

+0

嘗試寫'[image1 release];'這行後添加image1來查看。例如:'... [self.view addsubview:image1]'並在下一行寫'[image1發佈]' – Krunal

+0

不起作用... – HML

0

你確定你不只是加載了太多到內存?這些圖像有多大?這聽起來不像泄漏,更像是裝載太多。

+0

每個圖像是200 KB(靠近)大... – HML

+0

和每個按鈕按下,我打電話給另一個15圖像... – HML

+0

當你看到內存錯誤出現時,你會說你裝載了多少個圖像?從大小的角度來看,你是否想過在進入時縮小尺寸,以便他們在應用中的內存空間變得更小?我不得不這樣做,因爲加載的圖像非常大,但我只需要它們縮略圖,通過調整它們進入時的大小,降低真正需要的真實大小,您可以節省相當多的內存並獲得整體可感知的速度。 – trumpetlicks