Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sanniv

macrumors newbie
Original poster
Apr 22, 2009
5
0
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:mad:"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.
 
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.
 
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.
 
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?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.