EAGLContext Memory Leak Fix for OpenGLES2.0 iOS

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
vivekSivamRP
Posts: 66
Joined: Sat Sep 29, 2012 11:58 am

EAGLContext Memory Leak Fix for OpenGLES2.0 iOS

Post by vivekSivamRP »

In my project's case i need to constantly create and delete irrlicht device,i.e to call 'device' = CreatDevice() and to dealloc the 'device', frequently. I got a memory leak of 0.6 MB when ever i create and delete the device. Fixed the leak with few changes,
Add the lines that starts with + symbol.

Code: Select all

 
// Class: CIrrDeviceiOS.mm
    CIrrDeviceIPhone::~CIrrDeviceIPhone()
    {
+        [(IrrIPhoneDevice*)DeviceM release];    
    }
 
(void) dealloc
{
// Need to dealloc the old context before creating another
+  if([EAGLContext currentContext] == context) 
+       [EAGLContext setCurrentContext:nil];           
+   [context release];                                              // If  Arc enabled Just use context = nil;
    [self deactivateAccelerometer];
    [self deactivateGyroscope];
    [self deactivateDeviceMotion];
    [motionManager release];
    [super dealloc];
}
 
Post Reply