开发者

IPhone App Crashes on Device but Works on Iphone

I am a beginner at this :)

I have an app which changes an image of a UIImageView when a button is pushed, each image is about 200 kb, when run in the simulator 开发者_如何学运维it runs ok, I can change the image many times with no problems.

When run on my device (ipod touch) it loads ok, it sluggishly gets through about 4 images and then it crashes. When I run it with the Allocations performance tool, it crashes when overall bytes reaches about 2.75 megs. Number of living allocations is about 8000 (is this high?).

My console reads this

Program received signal:  “0”.
Data Formatters temporarily unavailable, will re-try after a 'continue'. (Unknown error loading shared library "/Developer/usr/lib/libXcodeDebuggerSupport.dylib")

I've also tried using the "leaks" performance tool and it doesn't find any leaks.

My .h file loads the image and uimageview like this:

@property(retain, nonatomic) IBOutlet UIImageView* myUIImageView;
@property(nonatomic, retain) UIImage *image;

Also, I release these like this:

- (void)dealloc {
[super dealloc];
[myUIImageView release];
[image release];
}

I also added in this, but it didn't seem to make any difference:

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    [myUIImageView release];
    [image release];
    // Release any cached data, images, etc that aren't in use.
}

I'm not sure what else to try at this point, any debugging techniques suggestions would be appreciated, also any pointers on how tackle memory issues like this would be hugely helpful, thanks!

Also, sorry forgot to add the image changing code:

- (IBAction)myButton {  

    static NSUInteger counter = 0;

    counter++;

    if (counter == 1) {
        myUIImageView.image = [UIImage imageNamed:@"image1.jpg"]; 
    }
    else  {
        myUIImageView.image = [UIImage imageNamed:@"image2.jpg"];
            counter = 0;
    }
}


Your image changing code looks fine, but I suggest these changes:

You should set myUIImageView to nil in your viewDidUnload method:

- (void)viewDidUnload {
    // release retained subviews of main view
    self.myUIImageView = nil;
}

In didReceiveMemoryWarning, you should set image to nil instead of sending a release:

self.image = nil;

Having [image release] in both didReceiveMemoryWarning and dealloc might cause a double release.

Also, don't release myUIImageView in didReceiveMemoryWarning.

Are you actually using the image ivar? It looks like you are assigning an image directly to the UIImageView. Having an unused ivar doesn't cause a problem, obviously, but I'm just wondering why it's there.


What code are you using to change the image? Make sure you are not re-alloc'ing the image or imageview.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜