ex28.pp 786 B

123456789101112131415161718192021222324252627282930
  1. Program ex28;
  2. { Program to demonstrate the TCollection.FreeAll 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. C^.FreeAll;
  23. Writeln ('Freed all objects. Memory available : ',Memavail);
  24. Writeln ('Lost : ',Initmem-Memavail,' bytes.');
  25. Dispose(C,Done);
  26. end.