turn_destroy_into_finalizer.nim 426 B

123456789101112131415161718192021222324252627
  1. discard """
  2. output: "turn_destroy_into_finalizer works"
  3. joinable: false
  4. """
  5. type
  6. Foo = object
  7. id: int
  8. var destroyed: int
  9. proc `=destroy`(x: var Foo) =
  10. #echo "finally ", x.id
  11. inc destroyed
  12. proc main =
  13. var r: ref Foo
  14. for i in 1..50_000:
  15. new(r)
  16. r.id = i
  17. if destroyed > 30_000:
  18. echo "turn_destroy_into_finalizer works"
  19. else:
  20. echo "turn_destroy_into_finalizer failed: ", destroyed
  21. main()