Re: [ft-devel] Why my memory is not been freed?
Jun.Wang wrote: Thanks very much for your kindly and carefully reply. I runs my programe on windows, I modified the FT_Done_FreeType, so I can call it several times to report current memory. With you reply, I know without FT_Done_FreeType there will be some memory not be released. If there any way to know the max memory size will be allocated by FreeType2? I havn't enough heap, I have to allocated a block of memory for freetype to keep the heap enough for my others program. But without the max memory size, I don't to how many size will be allocated. I just want to know the max maximum memory footprint on my programe beginning There is the record in the finally memory report, but it doesn't help to me. Why not write a simple wrapper using FT_Memory that counts the memory allocated, and then calls malloc/free? You will have to initialize the faces and the library in a slightly different way, probably. ___ Freetype-devel mailing list Freetype-devel@nongnu.org http://lists.nongnu.org/mailman/listinfo/freetype-devel
Re: [ft-devel] Why my memory is not been freed?
I use Arial.ttf. I uploaded my test project. Please Check. http://www.nabble.com/file/p22413476/GenfontData.rar I slightly modified (and formatted) your program so that it runs without errors using g++ -- in particular, g++ doesn't like jumps which cross an initialization. I compiled with g++ -Wall -O0 -g \ -o GenfontData \ GenfontData.cpp \ -l freetype (with proper -I and -L options to set the include and library directories) using the current CVS version of FreeType. BTW, have you ever run your example by yourself? In its unmodified form it always crashes due to the redundant FT_Done_FreeType call right before the `OUT0' label. Besides that, everything is fine! Sorry that I don't have time to modify FreeType as indicated by you for the tests. Attached you can see the output of valgrind. The call was valgrind ./GenfontData GenfontData.out 2 GenfontData.log It reports that there is no memory leak. Werner PS: The next time please send a *simple* C or C++ source file -- I don't need a complete project since I don't use Windows. In your example, there's far too much stuff which is not related to the very problems you have with FreeType. // GenfontData.cpp : Defines the entry point for the console application. // #include ft2build.h #include freetype/freetype.h #define TTF_FONT_SIZE (48) static FT_Library g_freetype2_library = NULL; static FT_Faceg_FTFace; static intg_MaxPixelHeight = 0; static intg_Baseline; static intg_Space; static intg_AverageWidth; #define ROUND_26_6_TO_INT(vale) ((vale + 63) 6) #define LOOKUP_CHAR(pf_, face_, ch_) (FT_Get_Char_Index(face_, ch_)) static void freetype2_setFontSize(int fontsize); static int freetype2_getGlyphSize(int glyph_index, int *pAdvance); static unsigned short aUnicode[] = { 0x0041, 0x0042, 0x0043, 0x0060, 0x0061, 0x0062 }; int main(int argc, char* argv[]) { FT_Error error; unsigned int uiUnicode; unsigned int uiUnicodeCount = sizeof(aUnicode) / sizeof(aUnicode[0]); error = FT_Init_FreeType(g_freetype2_library); if (error) { g_freetype2_library = NULL; printf(There is some err or when Init Library...); return 1; } error = FT_New_Face(g_freetype2_library, arial.ttf, 0, g_FTFace); if (error) { goto OUT; } error = FT_Select_Charmap(g_FTFace, FT_ENCODING_UNICODE); if (error) { printf(\nFT_Select_Charmap error!); goto OUT0; } freetype2_setFontSize(TTF_FONT_SIZE); printf(\nint g_MaxPixelHeight = %d;, g_MaxPixelHeight); printf(\nint g_Baseline = %d;, g_Baseline); printf(\nint g_AverageWidth = %d;, g_AverageWidth); printf(\n//-); printf(\n//-); for (uiUnicode = 0; uiUnicode uiUnicodeCount; uiUnicode++) { int currChar = LOOKUP_CHAR(NULL, g_FTFace, aUnicode[uiUnicode]); error = FT_Load_Glyph(g_FTFace, currChar, FT_LOAD_RENDER); if (error) { printf(\nFT_Load_Glyph error, unicode = 0x%04X!, aUnicode[uiUnicode]); goto OUT0; } if (g_FTFace-glyph-format != FT_GLYPH_FORMAT_BITMAP) { printf(\nFT_Load_Glyph error, format = %d!, g_FTFace-glyph-format); goto OUT0; } FT_Bitmap *bitmap = g_FTFace-glyph-bitmap; int iPixMode = g_FTFace-glyph-bitmap.pixel_mode; int bitmap_top = g_FTFace-glyph-bitmap_top; int bitmap_left = g_FTFace-glyph-bitmap_left; int bitmap_rows = bitmap-rows; int bitmap_width = bitmap-width; int bitmap_pitch = bitmap-pitch; unsigned char* pucBuf = bitmap-buffer; if (bitmap_rows g_MaxPixelHeight) { bitmap_rows = g_MaxPixelHeight; } //printf glyph data printf(\nunsigned short unicode_%d = 0x%04X;, uiUnicode, aUnicode[uiUnicode]); printf(\nintiPixMode_%d = %d;, uiUnicode, iPixMode); printf(\nintbitmap_top_%d = %d;, uiUnicode, bitmap_top); printf(\nintbitmap_left_%d = %d;, uiUnicode, bitmap_left); printf(\nintbitmap_rows_%d = %d;, uiUnicode, bitmap_rows); printf(\nintbitmap_width_%d = %d;, uiUnicode, bitmap_width); printf(\nintbitmap_pitch_%d = %d;, uiUnicode, bitmap_pitch); printf(\n/*); printf(\n); int iRow, iLine; for (iRow = 0; iRow bitmap_rows; iRow++) {
Re: [ft-devel] Why my memory is not been freed?
Bugzilla from w...@gnu.org wrote: Please upgrade to version 2.3.7 (or the current CVS or 2.3.9 next week) and try again. Werner I use ver2.3.7 test again. Follows are the memory report: //only 1 character FreeType Memory Dump: current=107502 max=107654 total=125708 count=63 //6 characters FreeType Memory Dump: current=106802 max=106802 total=118386 count=63 I use Arial.ttf. I uploaded my test project. Please Check. http://www.nabble.com/file/p22413476/GenfontData.rar GenfontData.rar The modules: //FT_USE_MODULE(autofit_module_class) FT_USE_MODULE(tt_driver_class) //FT_USE_MODULE(t1_driver_class) //FT_USE_MODULE(cff_driver_class) //FT_USE_MODULE(t1cid_driver_class) //FT_USE_MODULE(pfr_driver_class) //FT_USE_MODULE(t42_driver_class) //FT_USE_MODULE(winfnt_driver_class) //FT_USE_MODULE(pcf_driver_class) //FT_USE_MODULE(psaux_module_class) //FT_USE_MODULE(psnames_module_class) //FT_USE_MODULE(pshinter_module_class) FT_USE_MODULE(ft_raster1_renderer_class) FT_USE_MODULE(sfnt_module_class) FT_USE_MODULE(ft_smooth_renderer_class) FT_USE_MODULE(ft_smooth_lcd_renderer_class) FT_USE_MODULE(ft_smooth_lcdv_renderer_class) //FT_USE_MODULE(bdf_driver_class) I modified the FT_Done_FreeType function to display not freed memory: FT_Done_FreeType( FT_Library library ) { if ( library ) { FT_Memory memory = library-memory; /* Discard the library object */ //FT_Done_Library( library ); /* discard memory manager */ FT_Done_Memory( memory ); } return FT_Err_Ok; } In the ftoption.h file, I disabled follows: //#define FT_CONFIG_OPTION_USE_LZW //#define FT_CONFIG_OPTION_USE_ZLIB #define FT_DEBUG_MEMORY -- View this message in context: http://www.nabble.com/Why-my-memory-is-not-been-freed--tp22383746p22413476.html Sent from the Freetype - Dev mailing list archive at Nabble.com. ___ Freetype-devel mailing list Freetype-devel@nongnu.org http://lists.nongnu.org/mailman/listinfo/freetype-devel
Re: [ft-devel] Why my memory is not been freed?
2009/3/7 Jun.Wang xjw...@sunmedia.com.cn I did the memory debug with a little modify. 1. In FT_Done_FreeType( FT_Library library ), I disabled the line: FT_Done_Library( library ), so the memory report will disaply the current memory. ??? 2. I call FT_Done_FreeType() before FT_Done_Face(), This is a bug in your program. After FT_Done_FreeType() is called, every memory allocated by the corresponding FT_Library should be released (with the exception of FT_Glyph objects allocated by the user, but you are responsible for free-ing them before FT_Done_FreeType()) Calling FT_Done_Face() after that is probably asking for a lot of trouble (i.e. waling dangling pointers in the heap). and I getted the follws report: //only load 1 character FreeType Memory Dump: current=776564 max=776795 total=781508 count=59 //load 35 diff characters FreeType Memory Dump: current=777225 max=777579 total=783118 count=59 //load 150K characters, there are some same characters FreeType Memory Dump: current=779033 max=780079 total=34608360 count=60 after the FT_Done_Face(g_FTFace), the current for above all are same: FreeType Memory Dump: current=42697 max=777579 total=783118 count=21 It Looks while don't do FT_Done_Face(), the memory will increase with the loaded numbers 3. I do the load as follows: for(i = 0; i Size; i++){ FT_Load_Glyph(g_FTFace, currChar[i], FT_LOAD_RENDER); bitmap = (g_FTFace-glyph-bitmap); uiPixMode = g_FTFace-glyph-bitmap.pixel_mode; bitmap_top = g_FTFace-glyph-bitmap_top; bitmap_left = g_FTFace-glyph-bitmap_left; bitmap_rows = bitmap-rows; darw(bitmap); } Is there function to free memory after every FT_Load_Glyph? If do FT_Done_Face() every time, then I need FT_New_Face every time also. My freetype2 lib is 2.2.1. Thanks for your reply. -- View this message in context: http://www.nabble.com/Why-my-memory-is-not-been-freed--tp22383746p22383746.html Sent from the Freetype - Dev mailing list archive at Nabble.com. ___ Freetype-devel mailing list Freetype-devel@nongnu.org http://lists.nongnu.org/mailman/listinfo/freetype-devel ___ Freetype-devel mailing list Freetype-devel@nongnu.org http://lists.nongnu.org/mailman/listinfo/freetype-devel
Re: [ft-devel] Why my memory is not been freed?
David Turner-5 wrote: This is a bug in your program. After FT_Done_FreeType() is called, every memory allocated by the corresponding FT_Library should be released (with the exception of FT_Glyph objects allocated by the user, but you are responsible for free-ing them before FT_Done_FreeType()) Calling FT_Done_Face() after that is probably asking for a lot of trouble (i.e. waling dangling pointers in the heap). Thanks for your reply. I know if the FT_Done_Face() is called only the memory allocated for library is not released. But If I called FT_Done_Face() I must call FT_New_Face again this will cause performance trouble with my programe. -- View this message in context: http://www.nabble.com/Why-my-memory-is-not-been-freed--tp22383746p22426213.html Sent from the Freetype - Dev mailing list archive at Nabble.com. ___ Freetype-devel mailing list Freetype-devel@nongnu.org http://lists.nongnu.org/mailman/listinfo/freetype-devel