Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. // Demonstrate a destructor.
  2. using System;
  3. class Destruct {
  4. public int x;
  5. public Destruct(int i) {
  6. x = i;
  7. }
  8. // Called when object is recycled.
  9. ~Destruct() {
  10. Console.WriteLine("Destructing " + x);
  11. }
  12. // Generates an object that is immediately destroyed.
  13. public void Generator(int i) {
  14. Destruct o = new Destruct(i);
  15. }
  16. }
  17. class DestructDemo {
  18. static void Main() {
  19. int count;
  20. Destruct ob = new Destruct(0);
  21. /* Now, generate a large number of objects. At
  22. some point, garbage collection will occur.
  23. Note: You might need to increase the number
  24. of objects generated in order to force
  25. garbage collection. */
  26. for(count=1; count < 100000; count++)
  27.  
  28.  
  29. ob.Generator(count);
  30. Console.WriteLine("Done");
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement