Garbage Collection

Prof. Harley Flanders harley at umich.edu
Sat Aug 30 18:39:00 CEST 2008


A question for the GPC list:

Suppose I have defined

type  Vec = array[1..1000] of Extended;  // 10,000 bytes

var  A, B, C, D: Vec;

function  Sum(const  A, B: Vec): Vec;

In the assignment

D := Sum(Sum(A, B), C);

there is an intermediate result Sum(A, B), going to an unnamed temporary
vector. 

Does garbage collection pick up that space?

Similar question with

operator  + (const  A, B: Vec) C: Vec;

D := (A+B)+C;

More complicated:  Delphi mode, so I have "Result" available

var  Zero: Vec;  // Zero[J] = 0  for all  J

function  Foo(A: Vec;  N: Word): Vec;

  var  B: Vec;

  begin
  if  N = 0  then  Result := Zero
  else  if  Odd(N)  then
    Result := A + Foo(A, N - 1)
  else 
    begin
    B := (Foo(A, N div 2)
    Result := B + B;
    end;
  end;  // Foo

Garbage collection handles this correctly?


Whatever the answers, how do I PROVE them by measuring stack, heap, or 
whatever?

Thanks,

HF

-- 
=============================
Prof. Harley Flanders
3533 Windemere Court
Ann Arbor, MI 48105-2867
Home: 734 668 1546
harley at umich.edu
=============================






More information about the Gpc mailing list