Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SFML2]sf::Font memory leak  (Read 2295 times)

0 Members and 1 Guest are viewing this topic.

Adi

  • Newbie
  • *
  • Posts: 3
    • View Profile
[SFML2]sf::Font memory leak
« on: January 10, 2010, 04:09:47 pm »
I found that using function LoadFromFile for sf::Font generates a memory leak (actually a 64 memory leaks for valid loading and 38 when file is not present via Visual Leak Detector 1.9b).

Call Stack:
Code: [Select]
   0x00A3F50A (File and line number not available): glPushAttrib
    0x00A4AD11 (File and line number not available): FT_Done_Memory
    0x00A77E81 (File and line number not available): TT_RunIns
    0x00A30732 (File and line number not available): FT_Load_Char
    0x00A32D94 (File and line number not available): FT_Open_Face
    0x00A33059 (File and line number not available): FT_New_Face
    c:\sfml2\src\sfml\graphics\font.cpp (93): sf::Font::LoadFromFile


Other leaks have info only about
Code: [Select]
0x00A3F50A (File and line number not available): glPushAttrib

So using debugger i discovered that in Cleanup function code responsible for cleaning looks that:
Code: [Select]
if(myRefcount)
{
//cleaning;
}


but myRefcount is set by default constructor to NULL and never set to any value (and in fact before loading from file CLeanup sets it to NULL again and leaves it that way) and cleaning functions are never called.

So a fast fix in LoadFromFile function and LoadFromMemory
Code: [Select]
// Cleanup the previous resources
    Cleanup();
myRefCount = new int;
*myRefCount = 1;

makes memory leaks no more :D

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[SFML2]sf::Font memory leak
« Reply #1 on: January 10, 2010, 04:51:39 pm »
This was such a stupid error, thanks :)
Laurent Gomila - SFML developer

 

anything