Do I have a memory leak? (SDL)

This is a discussion on Do I have a memory leak? (SDL) within the Game Programming forums, part of the General Programming Boards category; If I do like this: Code: screen = SDL_SetVideoMode(....); /*LOTS OF CODE Time to change videomode*/ screen = SDL_SetVideoMode(....); I ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    80

    Do I have a memory leak? (SDL)

    If I do like this:

    Code:
    screen = SDL_SetVideoMode(....);
    
    /*LOTS OF CODE
    Time to change videomode*/
    
    screen = SDL_SetVideoMode(....);
    I use the same pointer both of these times, do I get a memory leak by doing this? I saw this in a tutorial...

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,586
    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.

    Code:
    WORD *Buffer=new WORD[10];
    WORD *Buffer2=new WORD[10];
    
    
    WORD *ptrBuffer=Buffer;
    
    ptrBuffer=Buffer2;
    
    
    delete [] Buffer;
    delete [] Buffer2;
    ptrBuffer=NULL;
    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.

    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.
    Last edited by VirtualAce; 03-02-2006 at 03:13 AM.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    80
    Ok, thank you very much.

  4. #4
    ---
    Join Date
    May 2004
    Posts
    1,379
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory leak in this case?
    By George2 in forum C++ Programming
    Replies: 3
    Last Post: 03-22-2008, 05:05 AM
  2. memory leak in the code?
    By George2 in forum C++ Programming
    Replies: 20
    Last Post: 01-13-2008, 05:50 AM
  3. Is this code memory leak free? ---> POSIX Threads
    By avalanche333 in forum C++ Programming
    Replies: 9
    Last Post: 04-13-2007, 03:19 PM
  4. Any Memory Leak Checking Tool?
    By George2 in forum C Programming
    Replies: 4
    Last Post: 06-21-2006, 11:02 PM
  5. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21