izan
izan

Reputation: 737

Memory leak in instruments

i have in my parser :

+(NSArray *)parseMethode:(NSData *)xmlData  {
...
 return [myNSArray autorelease];
}

and in an other controller i have done this :

@synthesize anOtherNSMutableArray;

- (void)requestFinished:(ASIHTTPRequest *)request
{

NSData *responseData = [self.currentRequest responseData];


self.anOtherNSArray = [MyClassParsers parseMethode:reponseData];
...

}

and when i lunch instruments it detect me a leak in the line :

self.anOtherNSArray = [MyClassParsers parseMethode:reponseData];

is there a leak in my code ??

thanks for your answers

Upvotes: 0

Views: 87

Answers (3)

Sylverb
Sylverb

Reputation: 939

I guess that you have defined this kind of property for anOtherNSArray :

@property (...,retain) NSArray *anOtherNSArray;

the retain property means that using the accessor will retain the value automatically ! using the accessor :

self.anOtherNSArray = something;

will do the same than not using the accessor but retaining the value :

anOtherNSArray = [someting retain];

You should either :

  • not defining the retain property for anOtherNSArray (use assign instead) if the value doesn't have to be retained here
  • not using the accessor (remove the "self.")
  • release the instance before setting a new value !

The last option is the easier and safest one (doing "self.anOtherNSArray = nil ;" as stated by Jhaliya will release the instance and set it to nil) !

Reading that may help you understanding a little bit more what are properties : http://cocoacast.com/?q=node/103

Upvotes: 0

Jhaliya - Praveen Sharma
Jhaliya - Praveen Sharma

Reputation: 31722

Try with below

self.anOtherNSArray = nil ;
self.anOtherNSArray = [MyClassParsers parseMethode:reponseData];

Upvotes: 1

Mehul Mistri
Mehul Mistri

Reputation: 15147

Just try this

 NSData *responseData = [self.currentRequest responseData] autorelease];

Upvotes: 0

Related Questions