PDA

View Full Version : [NSMutableArray release] crashes ?????




sanniv
Apr 23, 2009, 01:02 AM
Hello Guys,

I am stuck in crashes. I m doing following thing in a function

NSMutableArray *myMutableArray=[[NSMutableArray alloc] initWithCapacity:0]];

for (int i=0;i<10;i++)
[myMutableArray addObject:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"img000%d.png",(start+i+1)] ofType:nil]]];

self.myImageView.animationImages=myMutableArray;

[myMutableArray removeAllObjects];

//[myMutableArray release];

I have around 50 images and I load only 10 at a time for a purpose, I am controlling this by "start" variable which contains the initial point. And I want to free previous loaded images while loading new ones.

But when I uncomment the release method My program crashes..
And if I do not release, my memory is not being freed, as I checked in Instruments, although there is not leak in Leaks but still object allocation goes on and on with overall system memory of 100 MB. And because of this I get Low Memory Warning in program when I test in the device. I don't know what is the problem here. Please let me know if anyone has resolution.

Thanks in advance.

Regards,
Sanniv.



BlackWolf
Apr 23, 2009, 08:27 AM
do you get any kind of helpful output in the console? like "trying to release already released object" or something?

try to take out the "removeAllObjects" line, it's unnecessary anyway.

But to be honest it should work even with that line in, so I think your problem is outside of the code you posted.

sanniv
Apr 23, 2009, 12:23 PM
No the problem is in this code only, thats I m sure..
because Crash occurs only when I uncomment the release method and if I comment the release method program works fine but it doesn't free the memory of previously loaded images and thats why I get Low Memory warning after playing some time...
So need some suggestions.

do you get any kind of helpful output in the console? like "trying to release already released object" or something?

try to take out the "removeAllObjects" line, it's unnecessary anyway.

But to be honest it should work even with that line in, so I think your problem is outside of the code you posted.

kalimba
Apr 23, 2009, 02:57 PM
There doesn't appear to be anything about the code you posted that would in and of itself cause a crash. I'm guessing that your crash is happening somewhere else outside of this code, and it's happening because you're accessing an array which you've released.

Have you stepped through the code in the debugger to determine precisely where the crash is occurring?

sanniv
May 4, 2009, 07:37 AM
I have found the right way to use UIImageView so that it will not leak....
here is the link: http://www.sannivs-iphone-programming-tips.blogspot.com/

I guess it help ....