   Memory leak in opengl?
  I'm making a game and i've just added the ability to switch resolutions in game. I call glDeletetTextures and erase all my textures.Kill the opengl window and make the window again, then reload all the textures.everytime I do this 15mb's get added to my game in the task manager.I start at 70mb in task manager and have 112 textures loaded.seems to be the same problem here:http://www.gamedev.net/community/forums/topic.asp?topic_id=184012But I don't understand how to only call glgentextures just once...   
  I'm sure that if there was a memory leak in OpenGL then it would have been discovered by now ... Think of all those hundreds of thousands of developers world-wide; academics, graphics professionals, whole development studios and some of the sharpest minds in the industry - you'd think they'd notice..No, this bug must be in your code somewhere. If you dont have memory diagnostics routines then now would be a great time to get them set up so you can hunt this bug down.It's not the best (well ok it's really slow), but I recommend Visual Leak Detector to drop in just to hunt down a bug like this. Sooner or later though you'll need something with a bit more power and speed to track down your memory leaks in debug or release builds.   ;  glDeleteTextures does not deallocate anything stored in CPU memory.To deallocate the CPU memory, you must delete[] it (assuming you allocated it with new[]).Are you sure you're not overwriting a pointer that contains the address of still-allocated memory? If you used the vector class to store array data instead of a pointer, you could side-step this common type of memory leak.   ;  yeah im using vectors for everything, no pointers. only time i use a pointer is to use it for loading bmp's.AUX_RGBImageRec *LoadBMP(char *Filename)// Loads A Bitmap Image{FILE *File=NULL;if (!Filename)// Make Sure A Filename Was Given{return NULL;// If Not Return NULL}File=fopen(Filename,"r");// Check To See If The File Existsif (File)// Does The File Exist?{fclose(File);// Close The Handlereturn auxDIBImageLoad(Filename);// Load The Bitmap And Return A Pointer}return NULL;// If Load Failed Return NULL}unsigned int LoadGLTexture(char *f)// Load Bitmaps And Convert To Textures{AUX_RGBImageRec *TextureImage[1];// Create Storage Space For The Texturememset(TextureImage,0,sizeof(void *)*1);// Set The Pointer To NULL// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quitif (TextureImage[0]=LoadBMP(f)){// Typical Texture Generation Using Data From The BitmapglBindTexture(GL_TEXTURE_2D, Textures.size());glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);// Linear FilteringglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);// Linear Filtering}if (TextureImage[0])// If Texture Exists{if (TextureImage[0]->data)// If Texture Image Existsfree(TextureImage[0]->data);// Free The Texture Image Memoryfree(TextureImage[0]);// Free The Image Structure}return Textures.size();}But I skpped this process entirely because i was able to fix the memory being eating. I just use devmode to change the screen resolution, then i resize my opengl scene then resize my window. and because i dont close my opengl window i dont have to reload any textures.I do have the freeimage library installed, i could use that for loading bmp's instead of this code, see if I get the same memory problem.[edit]Ok i looked at my TGA load function (from nehe lesson #24)and he doesn't free the data after he loads it. (unsigned char *texture_imageData;)unsigned int R_LoadTexture(char *tfile){unsigned charTGAheader[12]={0,0,2,0,0,0,0,0,0,0,0,0};unsigned charTGAcompare[12];unsigned charheader[6];unsigned intbytesPerPixel;unsigned intimageSize;unsigned inttemp;unsigned inttype=GL_RGBA;unsigned int texture_width, texture_height, texture_texID, texture_bpp;unsigned char *texture_imageData;FILE *file;file = fopen(tfile, "rb");if(!file){return -1;}if(file==NULL ||fread(TGAcompare,1,sizeof(TGAcompare),file)!=sizeof(TGAcompare) ||memcmp(TGAheader,TGAcompare,sizeof(TGAheader))!=0||fread(header,1,sizeof(header),file)!=sizeof(header)){if (file == NULL)return -1;else{fclose(file);return -1;}}texture_width  = header[1] * 256 + header[0];texture_height = header[3] * 256 + header[2]; if(texture_width<=0||texture_height<=0||(header[4]!=24 && header[4]!=32)){fclose(file);return -1;}texture_bpp= header[4];bytesPerPixel= texture_bpp/8;imageSize= texture_width*texture_height*bytesPerPixel;texture_imageData=(GLubyte *)malloc(imageSize);//if the texture didn't load or the file is corruptif(texture_imageData==NULL ||fread(texture_imageData, 1, imageSize, file)!=imageSize){if(texture_imageData!=NULL)free(texture_imageData);fclose(file);return -1;}for(unsigned int i=0; i<int(imageSize); i+=bytesPerPixel){temp=texture_imageData;texture_imageData = texture_imageData;<br>texture_imageData = temp;<br>}<br><br>fclose (file);<br><br><br>glBindTexture(GL_TEXTURE_2D, Textures.size());<br>glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);<br>glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);<br>glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);<br>glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);<br><br><span class="cpp-keyword">if</span> (texture_bpp==<span class="cpp-number">24</span>)<br>type=GL_RGB;<br><br>gluBuild2DMipmaps(GL_TEXTURE_2D, type, texture_width, texture_height, GL_RGBA, GL_UNSIGNED_BYTE, texture_imageData);<br><br><span class="cpp-keyword">return</span> Textures.size();<br><br><br><br></pre></div><!–ENDSCRIPT–><br><br>That has to be me memory leak.<br><br><!–EDIT–><span class=editedby><!–/EDIT–>[Edited by - ViperG on August 30, 2007 2:03:46 PM]<!–EDIT–></span><!–/EDIT–>;  the glaux library was quickly hacked together many many years ago, it was superceeded by glut (which is many years old, so that gives u an idea how old glaux is :) )glaux has many problems/issues. mem leaks being one i seem to remember+ no i dont know why nehe used glaux   ;  Yes, I believe that the aux function is the source of your memory leak.I dare say NeHe used glaux because at the time he (a) didn't know better and (b) didn't know of another method of loading images. Unfortunately the fall out of this is that many people who read the tutorials come away using it.   ;  Alright. I already switched my game over to tiff and jpegs so not going to be using aux anymore anyways.   ;Quote:Original post by TheGilbI'm sure that if there was a memory leak in OpenGL then it would have been discovered by now ... Think of all those hundreds of thousands of developers world-wide; academics, graphics professionals, whole development studios and some of the sharpest minds in the industry - you'd think they'd notice..OpenGL itself cannot have a leak. OpenGL is a specification. The OpenGL implementation on your system (a.k.a the driver) could have a memory leak.However the other posters have already demonstrated that is not the case.