Thread: Trying to solve my memory leaks

  1. #16
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    My guess is that LoadTexture has a related function to "delete" a texture in some way - exactly what it is called should be part of the documentation for the library you are using. This is what you should called to "destroy" the texture - note that there may well be other resources tied to a texture, such as a "texture object" in the graphics library or graphics driver, so there's further reasons to destroy it properly.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  2. #17
    Registered User
    Join Date
    Aug 2005
    Posts
    96
    Quote Originally Posted by h3ro View Post
    LoadTexture is in a library I dont have access to. All i know is that is take a BYTE pointer and that it should again be deleted with the array method
    What is the array method?

    delete[]

    free()?

    Mind giving us the link to the documentation?

  3. #18
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    Something weird most be happening. I can use the class functions in the Sprite class that I have created before, but if i try to add a new one, i get an error (same as before)
    Code:
    If I add 
    void Sprite::foo()
    {
    // Do noting
    }
    
    and call it:
    spriteList[0]->foo();
    
    I get an error.
    But if I use one of the older functions, it works fine

  4. #19
    Registered User
    Join Date
    Aug 2005
    Posts
    96
    Maybe your sprite isn't allocating memory correctly?

  5. #20
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    Im sorry, but I cant post a link to the documentation, but it says that caller of the loadTexture function has to delete the returned data them self. And that it should be deleted using the array method.

    Also, there is no deleteTexture function or something like that.

    Maybe your sprite isn't allocating memory correctly?
    I think it does, as I can draw to the texture without any problems. Its just deleting it that is hard.

    EDIT:
    What might be a reason for non of my new functions working? Like the foo() example

  6. #21
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by h3ro View Post
    Im sorry, but I cant post a link to the documentation, but it says that caller of the loadTexture function has to delete the returned data them self. And that it should be deleted using the array method.

    Also, there is no deleteTexture function or something like that.


    I think it does, as I can draw to the texture without any problems. Its just deleting it that is hard.

    EDIT:
    What might be a reason for non of my new functions working? Like the foo() example
    You'd have to post a complete, compilable example of what is going wrong - although the likely scenario is that you end up finding it yourself if you try to create this - but it's hard to guess what goes on in "..." that you haven't posted, and I suspect:
    1. You are not too keen on posting it.
    2. I'm certainly not keen on reading loads of code to find what's wrong.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #22
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    Code:
    You'd have to post a complete, compilable example of what is going wrong - although the likely scenario is that you end up finding it yourself if you try to create this - but it's hard to guess what goes on in "..." that you haven't posted, and I suspect:
    1. You are not too keen on posting it.
    2. I'm certainly not keen on reading loads of code to find what's wrong.
    I cant post my entire code or the needed libraries needed to compile it due to copy rights. I tried to take as much out as possible, and I can use new functions now, but I still get the memory loss even though I call the destructor for the sprites when the program closes.

    Sorry for not posting the needed files, but thanks a lot for the help

  8. #23
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I think the correct thing to do is to call "delete [] spritedata" - but I'm not 100% sure.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #24
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    Reworked the whole thing and removed a pointer that casued me nothing but trouble.

    matsp: Your right, its delte[]

    Its working now, with no memory leaks.

    Thanks a lot to matsp and sethjackson!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assignment Operator, Memory and Scope
    By SevenThunders in forum C++ Programming
    Replies: 47
    Last Post: 03-31-2008, 06:22 AM
  2. Memory Leaks?
    By jimmymax in forum C++ Programming
    Replies: 3
    Last Post: 11-23-2007, 03:57 AM
  3. Question about Memory Leaks with *char
    By Diamonds in forum C++ Programming
    Replies: 11
    Last Post: 12-16-2002, 07:00 AM
  4. Is it necessary to write a specific memory manager ?
    By Morglum in forum Game Programming
    Replies: 18
    Last Post: 07-01-2002, 01:41 PM
  5. Memory leaks
    By Eber Kain in forum C++ Programming
    Replies: 3
    Last Post: 12-20-2001, 12:58 PM