Results 1 to 9 of 9

Thread: Memory leak in CL_Font 2.3.2

  1. #1
    Squire
    Join Date
    Sep 2011
    Location
    Poland
    Posts
    16

    Default Memory leak in CL_Font 2.3.2

    Hello fellow developers.
    I've stumbled upon a huge memory leak while creating a debbug console for the game in works.

    After a short research i've found out that this piece of code causes the problem:
    Code:
    void displayFps()
    {
      CL_FontDescription font_desc;
      font_desc.set_typeface_name("tahoma");
      font_desc.set_subpixel(false);
      font_desc.set_height(25);
    
      CL_Font_System font(gc,font_desc); // causes raise of allocated memory at every execution of the function.
      font.draw_text(gc,10,10,"fps"); // causes raise of allocated memory at every execution of the function.
    }
    The following code executes at every frame of the application, causing the allocated memory to raise from 30 MB to whopping 600 MBs in a really short time.
    It is also noticable in an example distributed in a 2.3.2 Clanlib package at \Examples\Display_Text\Font. To reproduce the leak in the example change the font couple of times.

    I haven't checked the Clanlib source yet, but it looks like the CL_Font destructor problem.

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    It sounds like the class is missing a virtual destructor somewhere.

    (I have not looked)

    Note, that code example will run slowly as the glyphs are recreated and uploaded to the GPU each frame. .... unless it's just a demonstration of the bug

  3. #3
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    I just created a test app under 2.4/Tests/Display/FontMemoryLeak, but I can't see any memory leaks under 2.2, 2.3 or 2.4 under Windows.

    Are you using Linux? If so, it seems the bug is somewhere in the linux implementation of the system fonts.

  4. #4
    Squire
    Join Date
    Sep 2011
    Location
    Poland
    Posts
    16

    Default

    I've created small test app as well. You can get it's source/Visual 2008 project here.
    I've got surprised. Received the same results as Sphair. CL_font was able to clean itself up without any problem.

    Notice the amount of memory the test app is using while holding the execution button. Isn't CL_Font tidying itself up? Although it goes back to normal after it stops iterating (what obviously doesn't happen, for instance, in \Examples\Display_Text\Font after you change the font couple of times.), frankly allocated memory shouldn't raise that much after some continuous calls.

    "Luckily" in my main project CL_Font doesn't tidy up at all <coughs>. I am figuring out what is causing this.

    Quote Originally Posted by rombust
    Note, that code example will run slowly as the glyphs are recreated and uploaded to the GPU each frame. .... unless it's just a demonstration of the bug
    I hope, as i love stressing my PC

    Quote Originally Posted by sphair
    Are you using Linux? If so, it seems the bug is somewhere in the linux implementation of the system fonts.
    Windows, Clanlib 2.3.2

  5. #5
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    Fonts are expensive objects to create - they contain alot of glyphs and textures needs to be created and uploaded etc. Common practise is to create them once and reuse them over the application - not create them when needed.

    If the memory usage goes down when you release the button, things sounds ok to me...

  6. #6
    Squire
    Join Date
    Sep 2011
    Location
    Poland
    Posts
    16

    Default

    The problem is that memory usage does not go down in some cases after CL_Font go out of bounds, causing a raising memory usage over time.

    I want to crate an object that maintains fonts.
    Really rough example would be a player reading books in-game which contains text which on the other hand is displayed using a given font.
    Font is loaded only once at the book open event. Then it is used to display the book contents until player decides to close the book.
    Players who open books too often would be required to restart the game to free the memory.

    loading all fonts from resource file at app start would fix it, but that's a lot memory to sacrifice. I really want to avoid this.

  7. #7
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    What you are suggesting should work.

    Also if your application contains a configurable font size at runtime, you would have to recreate the font. (Else you would very quickly run out of memory).

    (I have not have time to look at the problem myself yet)

    For interest, how are you recording memory usage?

    I noticed that in your example application, it does not contain any calls to ::GetProcessMemoryInfo

    The windows task manager memory usage can be misleading.

  8. #8
    Squire
    Join Date
    Sep 2011
    Location
    Poland
    Posts
    16

    Default

    I use RamMap and process explorer.
    Thanks for mentioning about the GetProcessMemoryInfo method. I am sure going to check it out .

  9. #9
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    "The problem is that memory usage does not go down in some cases after CL_Font go out of bounds"

    I guess you'll have to do some more digging to try to come up with an exact case that can be reproduced easily every time...

Similar Threads

  1. Bug in 2.1? CL_Font::get_text_size
    By Nightwind0 in forum Official ClanLib SDK Forums
    Replies: 3
    Last Post: 01-20-2010, 10:14 PM
  2. Video Memory
    By EdK in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 06-14-2008, 08:39 PM
  3. Big memory leak in CL_PNGProvider::save
    By FluXy in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 05-01-2008, 03:12 PM
  4. I need help using CL_Font with a System font on the Mac
    By eoliveri in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 08-07-2007, 01:59 PM
  5. Memory Leaks
    By in forum Funeral Quest
    Replies: 9
    Last Post: 03-06-2007, 11:00 AM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •