I have a problem like that :
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSData *data;
NSString *file1 = [[NSBundle mainBundle] pathForResource:
[NSStringstringWithFormat:@"originimg_%d.jpg",i] ofType:nil]] ;
UIImage *image1 = [[UIImage alloc]initWithContentsOfFile:file1];
data = UIImageJPEGRepresentation(image, 0.7);
// do sth with data ...
[image1 release];
image1 = nil;
[pool drain];
pool = nil;
if(data)
NSLog(@"still exist");
I checked whether data still exist in memory, (I expected it is removed after i drain the autorelease pool) but it still existed :(. Do you have any idea how to remove that data ?
I assume you omitted
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
before the quoted code.You should release
image1
before sending[pool drain]
because you allocated it. Thedata
object is autoreleased, which means it gets released in[pool drain]
. However, releasing the object does not magically set all the pointers to the object to nil, sodata
points to a deallocated object. Just for kicks, try the following instead of the last line:Your app should crash at this line because you can't send messages to deallocated objects.