how to avoid memory leaking
maarten van damme
maartenvd1994 at gmail.com
Sun May 12 15:05:34 PDT 2013
aren't you guys all getting tons of internal error's as soon as you combine
dynamic arrays with static arrays? It seems as if these things are
completely seperate things, but their syntax sugests a more closely related
connection. I really find it confusing...
So, after reducing, I am very certain that at least one problem comes from
generating a png, the code used is here available :
https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff/blob/master/png.d
seeing as this is pure d, am I right in assuming there should never be any
memory leaks when using this?
The reduced loop that only generates images is here :
TrueColorImage i= new TrueColorImage(width,height);
PNG* png;
double[][4] curtrans;
while(true){
curtrans=generateTransformationMatrix();
for(int y=0;y<height;y++)
for(int x=0;x<width;x++)
i.data[(y*width+x)*4..y*width+x)*4+4]=colorify(applyTransformation(transformXY(x,y),curtrans)).dup[0..3]
~ 255;
// and finally write the data to a png file
png = pngFromImage(i);
//std.file.write("images/"~toHexString(md5Of(curtrans))~".png",
writePng(png));
}
if you comment out "png = pngFromImage(i)" the program appears to not blow
up over time. I think the ice come from assiging a slice of a dynamic array
to a slice of a static array (hence the .dup). (I'll try reducing it with
dustmite)
2013/5/12 Benjamin Thaut <code at benjamin-thaut.de>
> Am 12.05.2013 21:05, schrieb maarten van damme:
>
>> This is ridiculous. Your solution appears to keep the memory somewhat
>> constant around 20mb-28mb untill it suddenly runs out of memory.
>> Literally out of nowhere.
>>
>> I have no idea what's causing everything, so I decided to get rid of the
>> window altogether and to try saving the images instead of displaying +
>> saving them. Now I run in "Internal error: ..\ztc\cgcs.c 343"...
>>
>> D is really dissapointing here. Maybe it's the gc having fun, maybe it's
>> something else, no way to know for sure. Having to give up on displaying
>> it altogether runs into internal error's.
>>
>
> As D is a relative new lagnauge stuff like this can happen. It would be
> great if you could reduce the compiler crash to a minimal test case using
> dustmite: https://github.com/**CyberShadow/DustMite<https://github.com/CyberShadow/DustMite>
> A description how to use it is aviable in the wiki. If you successfully
> reduced the compiler error please fill in a bug report at
> http://d.puremagic.com/issues/
>
> --
> Kind Regards
> Benjamin Thaut
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20130513/ef7f8221/attachment-0001.html>
More information about the Digitalmars-d-learn
mailing list