IPhone CGRect Memory Load

On an iPhone .. Why is code like this causing a memory leak? after 2 minutes, the net bytes have doubled. All I do is move the ball around the screen with the NSTimer calling the method below.

Any ideas?

- (void)nextFrame:(NSNotification *)notification {
    ballInstance.frame = CGRectMake(value, 0,  320, 480);
}

      


here is the "complete" code, new project, still behaves the same. It moves the jpg around the screen, and since it really consumes memory massively. If I remove "++" from "value" that's ok. (there are static graphics in other words) So ... is the image a cached question? If so, how can I stop it from reaching astronomical proportions?

- (void)applicationDidFinishLaunching:(UIApplication *)application {    


    [window makeKeyAndVisible];

    NSTimer * nSTimer =[NSTimer scheduledTimerWithTimeInterval: .02
         target: self
       selector: @selector(tick)
       userInfo: nil
        repeats: YES];
    value =0;
}

- (void)tick {
    NSLog(@"tick");
    myOutlet1.frame = CGRectMake(value++, 0,  320, 480);
}

      

+2


source to share


4 answers


The published code has no leak. The problem is elsewhere.



If you know there is a leak inside nextFrame:

, it should be in -[Ball setFrame:]

, because this is the only message sent by this method.

+8


source


The leak is not present in the code you are showing, especially if it frame

is a property @synthesized

. You either need to show more code, or spend some time with the tools to figure out what's going on and where it stands out.



+3


source


According to Apple:

This is a bug in iPhone OS 3.0. The
allocator for the graphics system reports realloc events as malloc events, so ObjectAlloc counts this as new objects that are almost never freed. I won't tell you why you might not see it when you add the Leaks tool, but
no tool would show a real leak for this.

Although I still don't know how to fix this.

+2


source


I have posted a complete sample application that more or less matches your "new project" example above. Can you take a look at this and see if they give you any ideas? I ran it on a simulator and on a device with no leak.

http://static.fatmixx.com/MemTestApp.zip

It actually looks like there is no leak here. I am building against iPhoneOS 3.1 - Debugging.

Sujal

+1


source







All Articles