soue / freetype-gl

Automatically exported from code.google.com/p/freetype-gl
Other
0 stars 0 forks source link

Unimplemented text_buffer_clear() + plausible memory leak #24

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I found this on Sunday while preparing the new build of my small project:

It appears that text_buffer_clear() is not implemented.  I needed it for the 
subpixel rendering in my code which is using text_buffers and needs to enter 
new text for every new frame.  

So I tried to implement it with simple:

vertex_buffer_clear(textBuffer->buffer);

I am not 100% sure if that is enough...

However, then I noticed a strange memory leak, which I traced to vertex buffer 
not clearing the "items" vector.

So, I simply added vector_clear( self->items) in vertex_buffer_clear().

I am not sure, however, if this is the right approach - but it definitely 
solved the leaking for me.

Original issue reported on code.google.com by dimko...@gmail.com on 25 Jun 2012 at 7:21

GoogleCodeExporter commented 9 years ago
The vector structure tries to minimize the number of malloc/free. When you 
request a clear, it does not really free the memory but only set size to 0 such 
that subsequent push_back won't need to re-alloc new memory.

This also means that individual items are not freed since the vector class is 
not responsible for the allocation, maybe this is the problem ?

Original comment by Nicolas.Rougier@gmail.com on 4 Jul 2012 at 9:05

GoogleCodeExporter commented 9 years ago
Finally, you were right, there was a need for a  vector_delete( self->items ) 
in vertex_buffer.
It has been fixed.

Original comment by Nicolas.Rougier@gmail.com on 19 Jul 2012 at 8:53