<div dir="ltr">I tried using gc.malloc and gc.free but got an invalidmemoryoperation exception when doing gc.free(data.ptr);<div style>Simply using gc.malloc like you proposed, the memory keeps growing. Is this a bug in the d garbage collector?</div>
<div style><br></div><div style>What's really strange though, is that the destructor of trueimagecolor (the class allocating the buffer) is getting called everytime...</div><div style>Does this mean that a destructor getting called still is no garantee that all data is getting free'd?</div>
<div style><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/5/12 Benjamin Thaut <span dir="ltr"><<a href="mailto:code@benjamin-thaut.de" target="_blank">code@benjamin-thaut.de</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Am 11.05.2013 01:18, schrieb maarten van damme:<div><div class="h5"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I'm trying to generate images and after displaying them I want to save<br>
them to a png file. I use parallelism to generate them asynchronously<br>
with the gui-thread to avoid blocking (don't know if this is really<br>
relevant).<br>
<br>
If I add a single line in the method where I generate the image that<br>
creates a class which allocates a pretty big array, slowly but surely<br>
the memory starts to rise until it ends in a spectacular out of memory<br>
exception. I always thought the garbage collector would deal with it.<br>
<br>
I tried reducing it but failed. Maybe I should let dustmite bite in it a<br>
bit later.<br>
How can I manually fix this? Is this a known bug in the garbage collector?<br>
<br>
btw, this code also caused segfaults on my  64 bit laptop on linux.<br>
How can I avoid this?<br>
<br>
main class:<br>
<a href="https://dl.dropboxusercontent.com/u/15024434/picturegenerator/generalised.d" target="_blank">https://dl.dropboxusercontent.<u></u>com/u/15024434/<u></u>picturegenerator/generalised.d</a><br>
<br>
zip file with everything ready to go to compile:<br>
<a href="https://dl.dropboxusercontent.com/u/15024434/picturegenerator/picturegenerator.zip" target="_blank">https://dl.dropboxusercontent.<u></u>com/u/15024434/<u></u>picturegenerator/<u></u>picturegenerator.zip</a><br>

</blockquote>
<br></div></div>
Try allocating the big array with:<br>
<br>
import core.memory;<br>
<br>
size_t imageSize = 1024*1024*3;<br>
auto imageData[] = (cast(ubyte*)GC.malloc(<u></u>imageSize , GC.BlkAttr.NO_SCAN)[0..<u></u>imageSize];<br>
<br>
Which will result in the big memory block not beeing scanned by the GC which should reduce the number of false positives during collection.<br>
<br>
If this doesn't work, use malloc / free of the c standard library to allocate and free the image data.<br>
<br>
Kind Regards<span class="HOEnZb"><font color="#888888"><br>
Benjamin Thaut<br>
</font></span></blockquote></div><br></div>