Dynamic Array Garbage collection

Daniel Keep daniel.keep.lists at gmail.com
Tue Feb 24 15:45:47 PST 2009



wolftousen wrote:
> I have a function defined as:
> 
> some_function(int[] array) { ... };  //this function does not ever modify values of array
> 
> When I call this function (once every program cycle) from an object using an array of type short:
> 
> //member variable in an object
> short[] x = new short[4];
> 
> //object calls this
> some_function([ x[0], x[1], x[2], x[3] ]);
> 
> After a few seconds of the program running, x[0] and x[1] values are set to 0 and a couple values of another array in the object are modified as well.
> 
> I have found that this bug is corrected by calling delete at the end of some_function of the variable array.  This tells me that the garbage collector is acting funny if I do not call delete on the array.  (I have watched the memory usage of the program and it doesn't fluctuate or pause or anything to signal the freeing/allocating of memory....)
> 
> Any Idea what is going on?

This sounds like something else is going on, although what I'm not sure.
  Maybe it's because I just woke up, but I can't see how that code could
compile anyway, since you can't pass a short[] to a function expecting
an int[].  Do you have a minimal, reproducible test case we can look at?

  -- Daniel


More information about the Digitalmars-d-learn mailing list