开发者

image picker controller takes insane memory even if released

my image picker is initialized like:

self.imgPicker = [[UIImagePickerController alloc] init];

self.imgPicker.allowsEditing = YES;

self.imgPicker.delegate = self;

self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

presentation:

[self initImagePickerFromLibrary]; ----(this calls the lines I have mentioned before)

      [self presentModalViewController:self.imgPicker animated:YES];


      [imgPicker release];

apple instrument says: before calling the picker memory used is 3 Mb.While the picker is in functi开发者_开发知识库on 12Mb.While editing image is 28Mb and my app crashes.Anyone did find a solution for this?


The one thing that comes to mind is that you're doing self. which may mean that your image picker is retained twice. Once, because you're allocating it and once because you're using a setter.

What does the @property line look like for imgPicker? Does it have retain? If it does, you should either change the first line in your first quote above to:

imgPicker = [[UIImagePickerController alloc] init];

I.e. removing self..

Also in your second line, you're releasing imgPicker directly. If your @property does have retain, you should instead just do:

self.imgPicker = nil;

The reason is that the @property synthesizing retains and releases objects when you set them. If you release the imgPicker without setting it to nil, and then, later on, try to set it to a new value, the system will attempt to release the already released object, and probably crash. The above is the same as doing:

[imgPicker release];
imgPicker = nil;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜