Re: memory allocation different in simulator and on the iPhone

2009-07-28 Thread Sven
UIImage* image = [UIImage imageNamed:fileName];

Loading an image with imageNamed causes the image to be cached in memory as
per the documentation.

I suggest using one of the alternatives to load your images and see how that
affects memory usage

./Sven

2009/7/24 Dragos Ionel 

> You are right, I was over releasing and maybe that was crashing the app.
> But still, even without [image release] the memory used by the app on
> iPhone
> is slowly increasing (like 3K for each image display). Maybe that is
> supposed to happen , maybe something is cached somewhere.
>
> But the good thing is it did not crash anymore after 200-300 images
> displayed.
>
> Thanks a lot,
> Dragos
>
>
> On Fri, Jul 24, 2009 at 3:14 AM, Jonathan del Strother <
> maill...@steelskies.com> wrote:
>
> > UIImage* image = [UIImage imageNamed:fileName];
> > UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
> > [image release];
> >
> > You're overreleasing the image there.  You sure the phone is dying
> > because it's out of memory, rather than because of that?
> >
> > On Fri, Jul 24, 2009 at 3:07 AM, Dragos Ionel
> > wrote:
> > > Hi,
> > > I am working on a animal encyclopedia on iPhone. One of the pages
> > displays
> > > one photo of an animal. When the user swipes the screen the image is
> > > replaced with another one.
> > >
> > > This works fine and when tested in the simulator with the Instrument
> for
> > > Object Allocation, all looks cool.
> > >
> > > When I tested on the real iPhone with Instrument, the memory used
> > increases
> > > slowly but constantly so that eventually the application dies.
> > >
> > > Here is the method that is doing the image changing (direction means if
> > the
> > > new image should come from left or from right). The class is a
> > > UIViewController
> > >
> > >
> > > -(void) displayAnimal: (int) animaIndex fromDirection:(int)direction{
> > >
> > >  crtIndex = animaIndex;
> > >
> > >  NSString* animalName = [[animalList objectAtIndex:animaIndex]
> > objectForKey:
> > > @"name"];
> > >
> > > NSString* fileName   = [[animalList objectAtIndex:animaIndex]
> > objectForKey:
> > > @"file"];
> > >
> > >  self.title = animalName;
> > >
> > >  //remove all the subviews
> > >
> > > for (UIView *view in self.view.subviews) {
> > >
> > > [view removeFromSuperview];
> > >
> > > }
> > >
> > >  UIView* backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0,
> 0,
> > 320,
> > > 480)];
> > >
> > > backgroundView.backgroundColor = [UIColor blackColor];
> > >
> > > [self.view addSubview:backgroundView];
> > >
> > > [backgroundView release];
> > >
> > >  UIImage* image = [UIImage imageNamed:fileName];
> > >
> > > UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
> > >
> > > [image release];
> > >
> > >  CGRect imageFrame = imageView.frame;
> > >
> > > imageFrame.origin = CGPointMake(320*direction,0);
> > >
> > > imageView.frame = imageFrame;
> > >
> > >  [self.view addSubview:imageView];
> > >
> > >
> > >  [UIView beginAnimations: nil context: @"identifier"];
> > >
> > > [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
> > >
> > > [UIView setAnimationDuration:0.5];
> > >
> > >  imageFrame.origin = CGPointMake(0,0);
> > >
> > > imageView.frame = imageFrame;
> > >
> > >  [UIView commitAnimations];
> > >
> > > [imageView release];
> > >
> > > }
> > >
> > > Can you see anything that is not right? Why is the memory allocation
> > showing
> > > different in simulator and on the iPhone?
> > >
> > > Thanks a lot,
> > > Dragos
> > > ___
> > >
> > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> > >
> > > Please do not post admin requests or moderator comments to the list.
> > > Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> > >
> > > Help/Unsubscribe/Update your Subscription:
> > >
> >
> http://lists.apple.com/mailman/options/cocoa-dev/maillist%40steelskies.com
> > >
> > > This email sent to maill...@steelskies.com
> > >
> >
> ___
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/svenito%40gmail.com
>
> This email sent to sven...@gmail.com
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: memory allocation different in simulator and on the iPhone [solved]

2009-07-24 Thread Dragos Ionel
Dear all,
Thank you all for the feedback. With that help and few hours of digging I
was able to solve the problem.

Just for reference here is what I was doing wrong;

1.

UIImage* image = [UIImage imageNamed:fileName];

UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

*[image **release**];*

If an image is created using imageNamed, then it is released automatically
so [image release] is incorrect;

2. At one point I was doing [titleLabel dealloc] for a UILabel instead of
[titleLabel release];


*How I discover where it was crashing*? I added NSLog in different part of
the code, run the application in simulator, and selected Hardware ->
Simulate Memory Warning.


*How I got tricked?* I looked at memory allocation and after each
imagedNamed there was a huge increase. That made me think that I have to
release the image which is not correct. The imageNamed is caching the image,
but it is clearing the cache when need be.

Your help was much appreciated!

Dragos


On Thu, Jul 23, 2009 at 10:07 PM, Dragos Ionel wrote:

> Hi,
> I am working on a animal encyclopedia on iPhone. One of the pages displays
> one photo of an animal. When the user swipes the screen the image is
> replaced with another one.
>
> This works fine and when tested in the simulator with the Instrument for
> Object Allocation, all looks cool.
>
> When I tested on the real iPhone with Instrument, the memory used increases
> slowly but constantly so that eventually the application dies.
>
> Here is the method that is doing the image changing (direction means if the
> new image should come from left or from right). The class is a
> UIViewController
>
>
> -(void) displayAnimal: (int) animaIndex fromDirection:(int)direction{
>
>  crtIndex = animaIndex;
>
>  NSString* animalName = [[animalList objectAtIndex:animaIndex]
> objectForKey:@"name"];
>
> NSString* fileName   = [[animalList objectAtIndex:animaIndex] objectForKey
> :@"file"];
>
>  self.title = animalName;
>
>  //remove all the subviews
>
> for (UIView *view in self.view.subviews) {
>
> [view removeFromSuperview];
>
> }
>
>  UIView* backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,
> 320, 480)];
>
> backgroundView.backgroundColor = [UIColor blackColor];
>
> [self.view addSubview:backgroundView];
>
> [backgroundView release];
>
>  UIImage* image = [UIImage imageNamed:fileName];
>
> UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
>
> [image release];
>
>  CGRect imageFrame = imageView.frame;
>
> imageFrame.origin = CGPointMake(320*direction,0);
>
> imageView.frame = imageFrame;
>
>  [self.view addSubview:imageView];
>
>
>  [UIView beginAnimations: nil context: @"identifier"];
>
> [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
>
> [UIView setAnimationDuration:0.5];
>
>  imageFrame.origin = CGPointMake(0,0);
>
> imageView.frame = imageFrame;
>
>  [UIView commitAnimations];
>
> [imageView release];
>
> }
>
> Can you see anything that is not right? Why is the memory allocation
> showing different in simulator and on the iPhone?
>
> Thanks a lot,
> Dragos
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: memory allocation different in simulator and on the iPhone

2009-07-24 Thread Jesse Armand
Try to use image allocation methods besides imageNamed

Jesse Armand

(http://jessearmand.com)



On Fri, Jul 24, 2009 at 9:07 AM, Dragos Ionel wrote:
> Hi,
> I am working on a animal encyclopedia on iPhone. One of the pages displays
> one photo of an animal. When the user swipes the screen the image is
> replaced with another one.
>
> This works fine and when tested in the simulator with the Instrument for
> Object Allocation, all looks cool.
>
> When I tested on the real iPhone with Instrument, the memory used increases
> slowly but constantly so that eventually the application dies.
>
> Here is the method that is doing the image changing (direction means if the
> new image should come from left or from right). The class is a
> UIViewController
>
>
> -(void) displayAnimal: (int) animaIndex fromDirection:(int)direction{
>
>  crtIndex = animaIndex;
>
>  NSString* animalName = [[animalList objectAtIndex:animaIndex] objectForKey:
> @"name"];
>
> NSString* fileName   = [[animalList objectAtIndex:animaIndex] objectForKey:
> @"file"];
>
>  self.title = animalName;
>
>  //remove all the subviews
>
> for (UIView *view in self.view.subviews) {
>
> [view removeFromSuperview];
>
> }
>
>  UIView* backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320,
> 480)];
>
> backgroundView.backgroundColor = [UIColor blackColor];
>
> [self.view addSubview:backgroundView];
>
> [backgroundView release];
>
>  UIImage* image = [UIImage imageNamed:fileName];
>
> UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
>
> [image release];
>
>  CGRect imageFrame = imageView.frame;
>
> imageFrame.origin = CGPointMake(320*direction,0);
>
> imageView.frame = imageFrame;
>
>  [self.view addSubview:imageView];
>
>
>  [UIView beginAnimations: nil context: @"identifier"];
>
> [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
>
> [UIView setAnimationDuration:0.5];
>
>  imageFrame.origin = CGPointMake(0,0);
>
> imageView.frame = imageFrame;
>
>  [UIView commitAnimations];
>
> [imageView release];
>
> }
>
> Can you see anything that is not right? Why is the memory allocation showing
> different in simulator and on the iPhone?
>
> Thanks a lot,
> Dragos
> ___
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/mnemonic.fx%40gmail.com
>
> This email sent to mnemonic...@gmail.com
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: memory allocation different in simulator and on the iPhone

2009-07-24 Thread Jonathan del Strother
I believe +[UIImage imageNamed] caches the image, so you would see
memory increasing.  I'm guessing that you eventually triggered a
memory warning, so UIImage dropped its caches, resulting in the crash
due to your over-release.

On Fri, Jul 24, 2009 at 1:04 PM, Dragos Ionel wrote:
> You are right, I was over releasing and maybe that was crashing the app.
> But still, even without [image release] the memory used by the app on iPhone
> is slowly increasing (like 3K for each image display). Maybe that is
> supposed to happen , maybe something is cached somewhere.
> But the good thing is it did not crash anymore after 200-300 images
> displayed.
> Thanks a lot,
> Dragos
>
>
> On Fri, Jul 24, 2009 at 3:14 AM, Jonathan del Strother
>  wrote:
>>
>> UIImage* image = [UIImage imageNamed:fileName];
>> UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
>> [image release];
>>
>> You're overreleasing the image there.  You sure the phone is dying
>> because it's out of memory, rather than because of that?
>>
>> On Fri, Jul 24, 2009 at 3:07 AM, Dragos Ionel
>> wrote:
>> > Hi,
>> > I am working on a animal encyclopedia on iPhone. One of the pages
>> > displays
>> > one photo of an animal. When the user swipes the screen the image is
>> > replaced with another one.
>> >
>> > This works fine and when tested in the simulator with the Instrument for
>> > Object Allocation, all looks cool.
>> >
>> > When I tested on the real iPhone with Instrument, the memory used
>> > increases
>> > slowly but constantly so that eventually the application dies.
>> >
>> > Here is the method that is doing the image changing (direction means if
>> > the
>> > new image should come from left or from right). The class is a
>> > UIViewController
>> >
>> >
>> > -(void) displayAnimal: (int) animaIndex fromDirection:(int)direction{
>> >
>> >  crtIndex = animaIndex;
>> >
>> >  NSString* animalName = [[animalList objectAtIndex:animaIndex]
>> > objectForKey:
>> > @"name"];
>> >
>> > NSString* fileName   = [[animalList objectAtIndex:animaIndex]
>> > objectForKey:
>> > @"file"];
>> >
>> >  self.title = animalName;
>> >
>> >  //remove all the subviews
>> >
>> > for (UIView *view in self.view.subviews) {
>> >
>> > [view removeFromSuperview];
>> >
>> > }
>> >
>> >  UIView* backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,
>> > 320,
>> > 480)];
>> >
>> > backgroundView.backgroundColor = [UIColor blackColor];
>> >
>> > [self.view addSubview:backgroundView];
>> >
>> > [backgroundView release];
>> >
>> >  UIImage* image = [UIImage imageNamed:fileName];
>> >
>> > UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
>> >
>> > [image release];
>> >
>> >  CGRect imageFrame = imageView.frame;
>> >
>> > imageFrame.origin = CGPointMake(320*direction,0);
>> >
>> > imageView.frame = imageFrame;
>> >
>> >  [self.view addSubview:imageView];
>> >
>> >
>> >  [UIView beginAnimations: nil context: @"identifier"];
>> >
>> > [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
>> >
>> > [UIView setAnimationDuration:0.5];
>> >
>> >  imageFrame.origin = CGPointMake(0,0);
>> >
>> > imageView.frame = imageFrame;
>> >
>> >  [UIView commitAnimations];
>> >
>> > [imageView release];
>> >
>> > }
>> >
>> > Can you see anything that is not right? Why is the memory allocation
>> > showing
>> > different in simulator and on the iPhone?
>> >
>> > Thanks a lot,
>> > Dragos
>> > ___
>> >
>> > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> >
>> > Please do not post admin requests or moderator comments to the list.
>> > Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>> >
>> > Help/Unsubscribe/Update your Subscription:
>> >
>> > http://lists.apple.com/mailman/options/cocoa-dev/maillist%40steelskies.com
>> >
>> > This email sent to maill...@steelskies.com
>> >
>
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: memory allocation different in simulator and on the iPhone

2009-07-24 Thread Dragos Ionel
You are right, I was over releasing and maybe that was crashing the app.
But still, even without [image release] the memory used by the app on iPhone
is slowly increasing (like 3K for each image display). Maybe that is
supposed to happen , maybe something is cached somewhere.

But the good thing is it did not crash anymore after 200-300 images
displayed.

Thanks a lot,
Dragos


On Fri, Jul 24, 2009 at 3:14 AM, Jonathan del Strother <
maill...@steelskies.com> wrote:

> UIImage* image = [UIImage imageNamed:fileName];
> UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
> [image release];
>
> You're overreleasing the image there.  You sure the phone is dying
> because it's out of memory, rather than because of that?
>
> On Fri, Jul 24, 2009 at 3:07 AM, Dragos Ionel
> wrote:
> > Hi,
> > I am working on a animal encyclopedia on iPhone. One of the pages
> displays
> > one photo of an animal. When the user swipes the screen the image is
> > replaced with another one.
> >
> > This works fine and when tested in the simulator with the Instrument for
> > Object Allocation, all looks cool.
> >
> > When I tested on the real iPhone with Instrument, the memory used
> increases
> > slowly but constantly so that eventually the application dies.
> >
> > Here is the method that is doing the image changing (direction means if
> the
> > new image should come from left or from right). The class is a
> > UIViewController
> >
> >
> > -(void) displayAnimal: (int) animaIndex fromDirection:(int)direction{
> >
> >  crtIndex = animaIndex;
> >
> >  NSString* animalName = [[animalList objectAtIndex:animaIndex]
> objectForKey:
> > @"name"];
> >
> > NSString* fileName   = [[animalList objectAtIndex:animaIndex]
> objectForKey:
> > @"file"];
> >
> >  self.title = animalName;
> >
> >  //remove all the subviews
> >
> > for (UIView *view in self.view.subviews) {
> >
> > [view removeFromSuperview];
> >
> > }
> >
> >  UIView* backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,
> 320,
> > 480)];
> >
> > backgroundView.backgroundColor = [UIColor blackColor];
> >
> > [self.view addSubview:backgroundView];
> >
> > [backgroundView release];
> >
> >  UIImage* image = [UIImage imageNamed:fileName];
> >
> > UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
> >
> > [image release];
> >
> >  CGRect imageFrame = imageView.frame;
> >
> > imageFrame.origin = CGPointMake(320*direction,0);
> >
> > imageView.frame = imageFrame;
> >
> >  [self.view addSubview:imageView];
> >
> >
> >  [UIView beginAnimations: nil context: @"identifier"];
> >
> > [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
> >
> > [UIView setAnimationDuration:0.5];
> >
> >  imageFrame.origin = CGPointMake(0,0);
> >
> > imageView.frame = imageFrame;
> >
> >  [UIView commitAnimations];
> >
> > [imageView release];
> >
> > }
> >
> > Can you see anything that is not right? Why is the memory allocation
> showing
> > different in simulator and on the iPhone?
> >
> > Thanks a lot,
> > Dragos
> > ___
> >
> > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> >
> > Please do not post admin requests or moderator comments to the list.
> > Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> >
> > Help/Unsubscribe/Update your Subscription:
> >
> http://lists.apple.com/mailman/options/cocoa-dev/maillist%40steelskies.com
> >
> > This email sent to maill...@steelskies.com
> >
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: memory allocation different in simulator and on the iPhone

2009-07-24 Thread Jonathan del Strother
UIImage* image = [UIImage imageNamed:fileName];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[image release];

You're overreleasing the image there.  You sure the phone is dying
because it's out of memory, rather than because of that?

On Fri, Jul 24, 2009 at 3:07 AM, Dragos Ionel wrote:
> Hi,
> I am working on a animal encyclopedia on iPhone. One of the pages displays
> one photo of an animal. When the user swipes the screen the image is
> replaced with another one.
>
> This works fine and when tested in the simulator with the Instrument for
> Object Allocation, all looks cool.
>
> When I tested on the real iPhone with Instrument, the memory used increases
> slowly but constantly so that eventually the application dies.
>
> Here is the method that is doing the image changing (direction means if the
> new image should come from left or from right). The class is a
> UIViewController
>
>
> -(void) displayAnimal: (int) animaIndex fromDirection:(int)direction{
>
>  crtIndex = animaIndex;
>
>  NSString* animalName = [[animalList objectAtIndex:animaIndex] objectForKey:
> @"name"];
>
> NSString* fileName   = [[animalList objectAtIndex:animaIndex] objectForKey:
> @"file"];
>
>  self.title = animalName;
>
>  //remove all the subviews
>
> for (UIView *view in self.view.subviews) {
>
> [view removeFromSuperview];
>
> }
>
>  UIView* backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320,
> 480)];
>
> backgroundView.backgroundColor = [UIColor blackColor];
>
> [self.view addSubview:backgroundView];
>
> [backgroundView release];
>
>  UIImage* image = [UIImage imageNamed:fileName];
>
> UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
>
> [image release];
>
>  CGRect imageFrame = imageView.frame;
>
> imageFrame.origin = CGPointMake(320*direction,0);
>
> imageView.frame = imageFrame;
>
>  [self.view addSubview:imageView];
>
>
>  [UIView beginAnimations: nil context: @"identifier"];
>
> [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
>
> [UIView setAnimationDuration:0.5];
>
>  imageFrame.origin = CGPointMake(0,0);
>
> imageView.frame = imageFrame;
>
>  [UIView commitAnimations];
>
> [imageView release];
>
> }
>
> Can you see anything that is not right? Why is the memory allocation showing
> different in simulator and on the iPhone?
>
> Thanks a lot,
> Dragos
> ___
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/maillist%40steelskies.com
>
> This email sent to maill...@steelskies.com
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com