How to fix D "memory leaks" -


so i've been searching solution problem time. i've written program take data 2 separate text files, parse it, , output text file , arff file analysis weka. problem i'm running function wrote handle data read , parsing operations doesn't de-allocate memory properly. every successive call uses additional 100mb or , need call function on 60 times on course of function. there way force d de-allocate memory, respect arrays, dynamic arrays, , associative arrays in particular?

an example of problem:

struct datum {      string foo;      int bar; }   datum[] collate() {     datum[] data;     int[] userdataset;     int[string] secondaryset;     string[] raw = splitlines(readtext(readfile)).dup;      foreach (r; raw) {         userdataset ~= parse(r);         secondaryset[r.split(",").dup] = parsesomeotherway(r);     }      data = dosomeothercalculation(userdataset, secondaryset);      return data; } 

are strings in returned data still pointing inside original text file?

array slicing operations in d not make copy of data - instead, store pointer , length. applies splitlines, split, , possibly dosomeothercalculation. means long substring of original file text exists anywhere in program, entire file's contents cannot freed.

if data you're returning small fraction of size of text file you're reading, can use .dup make copy of string. prevent small strings pinning entire file's contents in memory.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -