Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 01-08-2010, 06:33 AM   #1 (permalink)
Johanovski
Divine avenger
 
Johanovski's Avatar
 
Join Date: Nov 2009
Location: Vic, Catalunya (Spain)
Posts: 320
Johanovski is on a distinguished road
Default glTexImage2D leaking like hell, any help?

Hi there!

I've just done a mega-memory trace of my app and I've found that every time game's images are loaded (each time you start the game from the main menu) living memory increases like 1 or 1.5 MB, which is quite critical! I've traced where these allocations came from and I've found that come from OpenGL's function glTexImage2D. Each call on this function allocates a 1MB Malloc which seems not to be released after that, so it keeps alive...
I've searched the whole code and I've found that this method is only used in a function inside the Texture2D.m class. Here is the function and the dealloc method (I think last one is correct, but I'm not sure so I copy it too):

Code:
// Texture2D.m
- (id) initWithData:(const void*)data pixelFormat:(Texture2DPixelFormat)pixelFormat pixelsWide:(NSUInteger)width pixelsHigh:(NSUInteger)height contentSize:(CGSize)size
{
	GLint					saveName;
	if((self = [super init])) {
		glGenTextures(1, &_name);
		glGetIntegerv(GL_TEXTURE_BINDING_2D, &saveName);
		glBindTexture(GL_TEXTURE_2D, _name);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		switch(pixelFormat) {
			
			case kTexture2DPixelFormat_RGBA8888:
				glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
				break;
			case kTexture2DPixelFormat_RGB565:
				glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, data);
				break;
			case kTexture2DPixelFormat_A8:
				glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, data);
				break;
			default:
				[NSException raise:NSInternalInconsistencyException format:@""];
			
		}
		glBindTexture(GL_TEXTURE_2D, saveName);
	
		_size = size;
		_width = width;
		_height = height;
		_format = pixelFormat;
		_maxS = size.width / (float)width;
		_maxT = size.height / (float)height;
	}					
	return self;
}
And the dealloc method:

Code:
- (void) dealloc
{
	if(_name)
	 glDeleteTextures(1, &_name);
	
	[super dealloc];
}
I've also found a strange thing that I don't know how it works and why it's like is...
The Texture2D.m class (which I've taken from a tutorial) seems to be split in some parts divided by the "@implementation" and "@end" words, so there are one for "Texture2D", one for "Texture2D (Image)", one for "Texture2D (Text)", and one for "Texture2D (Drawing)", and I have to say that only the "Texture2D" and the "Texture2D (Drawing)" parts have a dealloc method before the "@end" line, I don't know it's what can be causing the leaks (sorry, maybe it's a quite newbie question, but I don't know exactly how this works and I'm get easily lost with this)...

Thanks in advance for your help!
Johanovski is offline   Reply With Quote
 

» Advertisements
» Online Users: 483
20 members and 463 guests
ArthurOff, Arty Tales, baja_yu, Bertrand21, bignoggins, David-T, dbramhall, djohnson, fanarin, Feldspar, habitatus, jbro, lgehrig1, LooN3y, myach, Nobbsy, pbart, shigaugi, skog, Thompson22
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,427
Threads: 94,024
Posts: 402,577
Top Poster: BrianSlick (7,978)
Welcome to our newest member, shakiraeb60
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:09 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.