UIImagePickerController does not release memory it occupies
Asked Answered
I

4

7

I saw this thing on using instruments for my app. When I profile my app, the initial memory occupied is 563 KB which is before UIImagePickerController pops up. There is one button on the first viewController which makes the UIImagePickerController appear.
As soon as UIImagePickerController appears, memory occupied goes upto 1.6 - 1.7 MB. If I select any image or cancel the UIImagePickerController, the memory occupied is still 1.6 - 1.7 MB which I believe should be 563 KB(or may be few KB's more).
Please see the below code I have used :

- (IBAction)chooseButtonPressed:(id)sender
{
    UIImagePickerController *pickerController = [[UIImagePickerController new]autorelease];
    [pickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
    [pickerController setDelegate:self];
}  

Why is the memory not being released?

enter image description here

Illyes answered 12/3, 2012 at 6:30 Comment(11)
Check this out go through this link.Donelu
Are you looking at the overall bytes occupied or the live bytes? For obvious reasons, overall bytes will never decrease...Hiers
Yes I am looking at overall bytes. But why won't it decrease?Illyes
It's a blind sum of all the bytes there have ever been added to the memory. When memory is released, the sum is not decreased. Right on the left of overall bytes, there must be a column of live bytes. Observe the values in this column and your question will be answered!Hiers
Both Live bytes and Overall bytes are same.Illyes
Actually, in xCode 4.x, Live bytes are two columns to the left of Overall bytes. Also, by Both Live bytes and Overall bytes are same., did you mean their values are same as each other or same with time?Hiers
There value is same all the time.Illyes
So did you observe live bytes vs. overall bytes ?Hiers
There is nothing to compare b/w them. They have same value.Illyes
I am tracking this problem, too. Using Xcode 4.3.2 for iOS SDK 4.3, 5.0 and 5.1. I still have this problem. One thing I notice is: if you have NO image in your photo library, it won't leak the memory (tested in Simulator). I also read the following threads without any solution yet. Let's keep tracking #6554725 #1447867 #9663139Reinforcement
Has any solution to this problem come to present? I'm having this problem, spent a lot of time trying to figure out whyGrimbald
H
1

We can't add images to comments so i'm putting this as an answer. The Live Bytes are always less than the Overall Bytes except till the first time a memory is deallocated. This can be seen from the image below.

enter image description here

I don't think there's anything wrong with your deallocation. I think you're just looking at the wrong values!

EDIT- I Think the problem might be somewhere else. To see the values I was seeing, you need to make a little change. As shown in the image below, you need to uncheck the option Only track active allocations to see the values you're looking for. If you still see 7.41 MB in Active allocations, then the problem is something else.

enter image description here

Hiers answered 12/3, 2012 at 8:51 Comment(5)
Please see my edited question. I have added a screen shot. Live Bytes is same as Overall BytesIllyes
@Illyes Please try the little change I've mentioned in my edit.Hiers
But how to uncheck this. Edit option is not available here.Illyes
I got the problem. I was checking leaks and not allocations on instruments. So the values came out same for live and overall bytes. But does that make sense?Illyes
The unchecking can happen only if the profiling is stopped. You can always start it again. I'm not sure why the live and overall bytes came out same when you were checking leaks. Probably because the Only track active allocations option was checked in that too.Hiers
A
1

Since you have given it autorelease option it will get added to the autorelease pool ... see what the documentation say..

The Application Kit creates an autorelease pool on the main thread at the beginning of every cycle of the event loop, and drains it at the end, thereby releasing any autoreleased objects generated while processing an event.

you can always release the picker in the delegate call like this..

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
...
...
[picker release];

}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
....
....
[picker release];

}
Admiral answered 12/3, 2012 at 6:45 Comment(1)
You are very right Ankit. What you have suggested is the latest I tried.Illyes
H
1

We can't add images to comments so i'm putting this as an answer. The Live Bytes are always less than the Overall Bytes except till the first time a memory is deallocated. This can be seen from the image below.

enter image description here

I don't think there's anything wrong with your deallocation. I think you're just looking at the wrong values!

EDIT- I Think the problem might be somewhere else. To see the values I was seeing, you need to make a little change. As shown in the image below, you need to uncheck the option Only track active allocations to see the values you're looking for. If you still see 7.41 MB in Active allocations, then the problem is something else.

enter image description here

Hiers answered 12/3, 2012 at 8:51 Comment(5)
Please see my edited question. I have added a screen shot. Live Bytes is same as Overall BytesIllyes
@Illyes Please try the little change I've mentioned in my edit.Hiers
But how to uncheck this. Edit option is not available here.Illyes
I got the problem. I was checking leaks and not allocations on instruments. So the values came out same for live and overall bytes. But does that make sense?Illyes
The unchecking can happen only if the profiling is stopped. You can always start it again. I'm not sure why the live and overall bytes came out same when you were checking leaks. Probably because the Only track active allocations option was checked in that too.Hiers
P
0

try this

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
[picker release];
Pathan answered 12/3, 2012 at 6:35 Comment(1)
no you tried autorelease instead of autorelease release memory at that time. and in - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info method write [picker dismissModalViewControllerAnimated:YES];Pathan
G
0

Did you set delegate to nil?

For more information you can refer to UIImagePickerConrtoller class reference

[picker release];
picker.delegate = nil ;

Hope this helps you.

Groth answered 12/3, 2012 at 7:13 Comment(5)
@Maulik: I edited the answer and added class reference for UIImagePickerController as the answer appeared under Low Quality Post.Brookins
@ParthBhatt: thanks... where did you found Low Quality Post ??? I don't know about it.. ;DGroth
@Groth It is under the review section. I was reviewing the Low quality posts and found yours and hence edited it.Brookins
@ParthBhatt: thanks again...Next time I'll take care about it... :DGroth
@Maulik: I have not changed your answer though as I can't completely change the answer of the poster. As it can cause him disadvantages and at times advantages in terms of reputation. :)Brookins

© 2022 - 2024 — McMap. All rights reserved.