In case the answer is obvious, please don't be hard on me, i'm still new to Cocoa.
I recompiled the iMedia framework to make use of garbage collection, which it officially supports, according to their issue tracker (tracker entry). iMedia parses iTunes' XML library file and loads everything into an NSDictionary (i call it "monster dictionary") - I guess there is no way to avoid the peak 100MB of memory usage when parsing the library, as long as I use iMedia. But AFAIK all of iMedia's objects should be gc'ed when my method is done.
Here it is:
- (NSArray*) allPlaylists {
NSMutableArray* playlists = [NSMutableArray array];
NSArray *allParsers = [IMBiTunesParser parserInstancesForMediaType:kIMBMediaTypeAudio];
for (IMBiTunesParser* parser in allParsers) {
IMBNode* rootnode = [parser nodeWithOldNode:nil
options:kIMBOptionNone
error:nil];
// XML file is read and monster dictionary in iMedia is populated:
[parser populateNode:rootnode options:kIMBOptionNone error:nil];
for (IMBNode* child in rootnode.subNodes) {
[playlists addObject:child];
}
[parser didStopUsingParser]; // this sets the monster dictionary to nil
}
return playlists; }
The playlist objects which are returned are very small, since children (tracks) are lazily loaded, so that should amount to some kB at the most. They do keep references to the parser, but the call to [parser didStopUsingParser] nullifies the reference to the 100MB monster dictionary.
Now to my question: Do I do something wrong in my code which disallows garbage collection, or is it likely that iMedia does not allow collection of the monster dictionary, by running a non-collected thread or something?