40media How to solve this memory leak (iPhone)?

How to solve this memory leak (iPhone)?

How to release this variable with no EXC_BAB_ACCESS ?

//First line create memory leak UIImage *ImageAvatar =  [[UIImage alloc] initWithData:[myg.imageData copy]]; Moins1 = ImageAvatar; //[ImageAvatar release]; if i release-> EXC_BAD_ACCESS 

Moins1 is a menber of the interface is declared like this :

UIImage *Moins1; ... @property (nonatomic, retain)   UIImage			*Moins1; 

UITableView frame height animation glitch


Should a property list be managed by its own model object?
It looks like the problem isn't the UIImage, although rather the NSData. How to remove NSString Related Memory Leaks? In Cocoa, any copy (or mutableCopy) method returns an object with a +1 retain count, meaning this you own it and are therefore responsible for releasing it.. XCode, iPhone, WebKit Framework - What am I missing? In your code, you're calling -copy on myg.imageData, although never releasing it. What describes NSNumberFormatter -maximumSignificantDigits? That's a classic case of a memory leak. mobile_fu rendering over AJAX so it seems Here's what I would did to fix it, plus with changing your syntax a bit:. iphone nslog corrupted data ivar:. Use a C++ file in Cocoa iPhone App
UIImage *Moins1; @property (nonatomic, retain) UIImage *Moins1; 
NSData * imageData = [myg.imageData copy]; UIImage * ImageAvatar = [[UIImage alloc] initWithData:imageData]; [imageData release]; [self setMoins1:ImageAvatar]; [ImageAvatar release]; 


You should not need to send -copy to the NSData object. UIImage does not keep a reference to the data around, it just reads it and produces an image. Sending -copy without -release is a memory leak.. However, this does not explain the EXC_BAD_ACCESS. Something else is going on, and not from the code you've posted..


There are two problems in your code. The copying of imageData as indicated by the another contrialthough ers, and the assignment to Moins1 field without retaining the object.. The assingment to Moins1 access the field directly, so you would need to did your own retaining. If you don't retain it and release it in the next line, then any subsequence access to the field results into a protection error.. You must use the property for assignment:.
UIImage *ImageAvatar =      [[UIImage alloc] initWithData:[[myg.imageData copy] autorelease]]; self.Moins1 = ImageAvatar; [ImageAvatar release]; 
Or you must also just did it in one line:.
self.Moins1 = [UIImage imageWithData:[[myg.imageData copy] autorelease]]; 


-(void )dealloc   {    if(self.Moins1!=nil)      {       self.Moins1 = nil;      }    } 
see when u commit and object a retain property its count is already 1 and when u allocate it its count becomes 2 so when the dealloc is called it will check if its nil and if its not nil make it nil .In this way it will commit the retain count of the variable to 0.

76 out of 100 based on 46 user ratings 806 reviews