memory management question -- releasing an object which has to be returned

Posted by ulag on Stack Overflow See other posts from Stack Overflow or by ulag
Published on 2010-06-05T17:39:43Z Indexed on 2010/06/05 17:42 UTC
Read the original article Hit count: 105

Filed under:

Hi,

I have an NSMutableArray called playlist. This is in a method called getAllPlaylists. The code is something like this:

-(NSMutableArray *)getAllPlaylists

{

//playlist is an instance variable

playlist = [[NSMutableArray alloc] init]; //memory leak here

.

.

//some code here which populates the playlist array

[playlist addObject: object1];

.

.

return playlist;

}

The array allocation step of playlist is causing a memory leak. In such a scenario where can i release this array? Or can i avoid allocation n initialization of playlist here by doing something else?

© Stack Overflow or respective owner

Related posts about iphone