Looking for some insight while fixing leaks...

Posts: 18
Joined: 2010.07
Post: #1
I've gotten to the point in my game where I need to start tidying up the loose ends, and try to take care of leaks. Luckily, I've only been able to detect a single leak in instruments, and I'm not sure it is even truly a leak. Right around the beginning of execution I get a leak from the QuartzCore library, with ensure_displays() being the Responsible frame. When I check the leaks and goto the heaviest backtraces, from my understanding it is happening within my GLView initframe method, which just sets up the CAEAGLLayer, initializes the EAGLContext, and initializes the separate components of my engine. The engine code is all written in C++, the only Obj-C is the context code and my NSUserDefaults code. Now, I'm guessing that the leak pertains to the context code (given it is from Quartz and pertains to the display) , as I manually allocate the the memory:

CAEAGLLayer* eaglLayer = (CAEAGLLayer*) self.layer;
        eaglLayer.opaque = YES;

        EAGLRenderingAPI api = kEAGLRenderingAPIOpenGLES2;
        m_context = [[EAGLContext alloc] initWithAPI:api];
        if (!m_context || ForceES1) {
            api = kEAGLRenderingAPIOpenGLES1;
            m_context = [[EAGLContext alloc] initWithAPI:api];
        if (!m_context || ![EAGLContext setCurrentContext:m_context]) {
            [self release];
            return nil;

However, this obviously doesn't get released until I'm done with the view, just before execution is terminated. So, am I understanding what instruments is telling me and debugging this correctly, or am I missing something? Thanks in advance for any help!
Quote this message in a reply
Posts: 3,591
Joined: 2003.06
Post: #2
Nothing obvious about that code snippet pops out at me, but I've been in the habit of missing the obvious recently Wink

Try using the Static Analyzer. It's really good at spotting Obj-C related leaks in my experience.

Also, if the leak is occurring in a system library, it has been my experience that you can safely ignore those since apparently it's okay for Apple's code to leak, especially if it's less than maybe a few hundred kilobytes over the life of the program.
Quote this message in a reply
Posts: 18
Joined: 2010.07
Post: #3
Alright, thanks for the info!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  does the app store accept games with leaks? aerospaceman 5 7,588 Mar 15, 2011 01:59 PM
Last Post: aerospaceman
  Advice on fixing memory leaks petemccabe 4 4,630 Jun 24, 2010 09:19 AM
Last Post: petemccabe
  Leaks program kendric 2 3,618 Jun 16, 2009 08:19 PM
Last Post: kendric
  Leaks in the waterworks. bmantzey 5 4,988 Feb 27, 2009 04:07 PM
Last Post: AnotherJake