Note that there are some explanatory texts on larger screens.

plurals
  1. POMassive Memory Leak - CocoaLibSpotify
    primarykey
    data
    text
    <p>I'm using the CocoaLibSpotify library to load album art for Spotify search results.</p> <p>Instruments reports no leaks, and static analysis isn't helping out either, and I've manually reviewed all of my code that deals with keeping track of loading the album art, yet, after loading a few hundred results, the app consumes over 100mb of memory and crashes.</p> <p>I believe that CocoaLibSpotify is keeping a cache of the images in memory, but there is no way that I have found of disabling the cache. There is a "flushCaches" method, which I've been calling each time I get a memory warning, but, it is ineffective.</p> <p>Here's what I'm using to load the album art, I keep a reference to all of the SPImage objects in an array, so that I can use them when serving up table view rows.</p> <pre><code>[self sendRequestToURL: @"http://ws.spotify.com/search/1/track.json" withParams: @{@"q": spotifySearchBar.text} usingMethod: @"GET" completionHandler: ^(id result, NSError *error) { //after the search completes, re-enable the search button, replace the searchResults, and // request the result table to reload the data spotifySearchBar.userInteractionEnabled = YES; [searchBar endEditing: YES]; [searchResults release]; int resultLength = [[result objectForKey: @"tracks"] count] &lt; 100 ? [[result objectForKey: @"tracks"] count] : 100; searchResults = [[[result objectForKey: @"tracks"] subarrayWithRange: NSMakeRange(0, resultLength)] retain]; for(int i = 0; i &lt; 100; i++) { [albumArtCache replaceObjectAtIndex: i withObject: [NSNull null]]; } for(NSDictionary *trackDict in searchResults) { NSString *trackURI = [trackDict objectForKey: @"href"]; [SPTrack trackForTrackURL: [NSURL URLWithString: trackURI] inSession: session callback: ^(SPTrack *track) { [SPAsyncLoading waitUntilLoaded: track timeout: kSPAsyncLoadingDefaultTimeout then:^(NSArray *loadedItems, NSArray *notLoadedItems) { if(track == nil) return; [SPAsyncLoading waitUntilLoaded: track.album timeout: kSPAsyncLoadingDefaultTimeout then:^(NSArray *loadedItems, NSArray *notLoadedItems) { if(track.album == nil) return; [SPAsyncLoading waitUntilLoaded: track.album.largeCover timeout: kSPAsyncLoadingDefaultTimeout then:^(NSArray *loadedItems, NSArray *notLoadedItems) { if(track.album.largeCover == nil) return; if(![searchResults containsObject: trackDict]) { NSLog(@"new search was performed, discarding loaded result"); return; } else{ [albumArtCache replaceObjectAtIndex: [searchResults indexOfObject: trackDict] withObject: track.album.largeCover]; [resultTableView reloadRowsAtIndexPaths: @[[NSIndexPath indexPathForRow: [searchResults indexOfObject: trackDict] inSection: 0]] withRowAnimation: UITableViewRowAnimationAutomatic]; } }]; }]; }]; }]; } [resultTableView reloadData]; }]; </code></pre> <p>And here is the code that deals with loading table view cells.</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: @"artistCell"]; if(cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleSubtitle reuseIdentifier: @"artistCell"] autorelease]; } cell.textLabel.text = [[searchResults objectAtIndex: indexPath.row] objectForKey: @"name"]; cell.detailTextLabel.text = [[[[searchResults objectAtIndex: indexPath.row] objectForKey: @"artists"] objectAtIndex: 0] objectForKey: @"name"]; if([albumArtCache objectAtIndex: indexPath.row] != [NSNull null]) { cell.imageView.image = ((SPImage *)[albumArtCache objectAtIndex: indexPath.row]).image; } else{ cell.imageView.image = nil; } return cell; } </code></pre> <p>I really have no idea what's going wrong. Any assistance would be greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload