ex30.pp 823 B

12345678910111213141516171819202122232425262728293031
  1. Program ex30;
  2. { Program to demonstrate the TCollection.Free method }
  3. Uses Objects,MyObject; { For TMyObject definition and registration }
  4. Var C : PCollection;
  5. M : PMyObject;
  6. I,InitMem : Longint;
  7. begin
  8. Randomize;
  9. C:=New(PCollection,Init(120,10));
  10. InitMem:=Memavail;
  11. Writeln ('Initial memory : ',InitMem);
  12. For I:=1 to 100 do
  13. begin
  14. M:=New(PMyObject,Init);
  15. M^.SetField(I-1);
  16. C^.Insert(M);
  17. end;
  18. Writeln ('Added 100 Items. Memory available : ',Memavail);
  19. Write ('Lost : ',Initmem-Memavail,' bytes.');
  20. Write ('(Should be 100*',SizeOF(TMyObject));
  21. Writeln ('=',100*SizeOf(TMyObject),')');
  22. With C^ do
  23. While Count>0 do Free(At(Count-1));
  24. Writeln ('Freed all objects. Memory available : ',Memavail);
  25. Writeln ('Lost : ',Initmem-Memavail,' bytes.');
  26. Dispose(C,Done);
  27. end.