www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - associative array re-use

reply ViktorKrescvohn <viktor_kv7 bhecn.net> writes:
i have a function that re-use same associative array over and over within a
loop. and i release the array with 'null' afther each loop, will that be a
problem of meamory leak after few thousands loop. sample function as below:

void[] [char[]] dict;
void[] [char[]] temp;

function test()
{
  for (..) {
    for (...) {
       temp[name]=value;
    }
    dict~=temp;
    temp=null;
  }
  ..do something with dict...
}

thank you for you help
Nov 26 2008
next sibling parent reply BCS <ao pathlink.com> writes:
Reply to ViktorKrescvohn,

 i have a function that re-use same associative array over and over
 within a loop. and i release the array with 'null' afther each loop,
 will that be a problem of meamory leak after few thousands loop.
 sample function as below:
 
 void[] [char[]] dict;
 void[] [char[]] temp;
 function test()
 {
 for (..) {
 for (...) {
 temp[name]=value;
 }
 dict~=temp;
 temp=null;
 }
 ..do something with dict...
 }
 thank you for you help
 

No, AA's are built in the GC heap so it can't leak.
Nov 26 2008
parent ViktorKrescvohn <viktor_kv7 bhecn.net> writes:
BCS Wrote:

 Reply to ViktorKrescvohn,
 
 i have a function that re-use same associative array over and over
 within a loop. and i release the array with 'null' afther each loop,
 will that be a problem of meamory leak after few thousands loop.
 sample function as below:
 
 void[] [char[]] dict;
 void[] [char[]] temp;
 function test()
 {
 for (..) {
 for (...) {
 temp[name]=value;
 }
 dict~=temp;
 temp=null;
 }
 ..do something with dict...
 }
 thank you for you help
 

No, AA's are built in the GC heap so it can't leak.

what about normal arrays, and thank you very much
Nov 26 2008
prev sibling parent reply "Jarrett Billingsley" <jarrett.billingsley gmail.com> writes:
On Wed, Nov 26, 2008 at 11:23 PM, ViktorKrescvohn <viktor_kv7 bhecn.net> wrote:
 what about normal arrays, and thank you very much

Everything you allocate is garbage-collected. Arrays, AAs, classes - _everything_.
Nov 26 2008
parent BCS <ao pathlink.com> writes:
Reply to Jarrett,

 On Wed, Nov 26, 2008 at 11:23 PM, ViktorKrescvohn
 <viktor_kv7 bhecn.net> wrote:
 
 what about normal arrays, and thank you very much
 

_everything_.

unless you break out malloc, but you basicly never need to.
Nov 27 2008