ex29.pp 843 B

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