Debugging memory leak.

David Brown dlang at davidb.org
Mon Oct 8 09:35:50 PDT 2007


On Mon, Oct 08, 2007 at 09:22:54AM -0700, Sean Kelly wrote:
> David Brown wrote:
>> Ideas for possibly fixing this:
>>   - Manually 'delete' these buffers.  In my instance, this wouldn't really
>>     be all that difficult since I know when they go out of use.
>>   - Call std.gc.hasNoPointers(void*) on the block.  I would think this is
>>     the case for a char[], but std.zlib.compress uses a void[], which the
>>     compiler can't make this assumption about.
>
> std.zlib should likely be changed to use a byte[] array instead.

I called delete on the result coming back from std.zlib.compress and it
seems to have gotten rid of the memory leak.  My guess is that on x86_64,
the address space is large enough that compressed data was unlikely to look
like pointers, but more likely to do so on a 32-bit platform.

So, I would call this a bug in std.zlib.  Even if it still returns the
void[], it should allocate as a byte[].

In my instance, calling delete on the block reduces the amount of work the
garbage collector needs to do, so probably is a good idea anyway.

Thanks,
David



More information about the Digitalmars-d mailing list