If I do like this:
I use the same pointer both of these times, do I get a memory leak by doing this? I saw this in a tutorial...Code:screen = SDL_SetVideoMode(....);
/*LOTS OF CODE
Time to change videomode*/
screen = SDL_SetVideoMode(....);
Printable View
If I do like this:
I use the same pointer both of these times, do I get a memory leak by doing this? I saw this in a tutorial...Code:screen = SDL_SetVideoMode(....);
/*LOTS OF CODE
Time to change videomode*/
screen = SDL_SetVideoMode(....);
Not that I can see. The only leak would be if SDL requires you to free the screen data or the pointer after you use it, or if that function somehow internally increases the reference count for the object.
As long as you don't use ptrBuffer to delete the object, you will be ok. But ptrBuffer does not cause a memory leak in this case.Code:
WORD *Buffer=new WORD[10];
WORD *Buffer2=new WORD[10];
WORD *ptrBuffer=Buffer;
ptrBuffer=Buffer2;
delete [] Buffer;
delete [] Buffer2;
ptrBuffer=NULL;
I pass an IDirect3DDevice9 interface pointer around in my engine and as long as each class understands that they can use the pointer, but they cannot release it or delete it, everything works just fine.
The danger is that any object could mistakenly delete or release the pointer in which case the whole system comes crashing down.
Ok, thank you very much. :)
antex: Doing that is how non-linux users change the screen resolution while the app is running. So AFAIK there is nothing wrong with doing that.