next up previous contents
Next: The Different Collectors Up: Smart Pointers & Garbage-Collected Previous: Object Creation

The Rules

Those were the basics. Here are the official rules for using Giggle in your code. As long as you follow these rules, Giggle can manage the destruction of your objects. If you break the rules, undefined behaviours will happen, & Giggle cannot be held responsible for any of it.

  1. Objects managed by Giggle must be allocated with ::operator new (size_t, CyberTiggyr::giggle::GarbageCollector &). Conversely, Giggle assumes that an object allocated with that operator is to be managed by Giggle.

  2. Giggle determines when to call the destructors for objects allocated under Giggle's control. Depending on the garbage collection algorithm you've chosen, this could be as soon as the object is ready to be destroyed or it might be very late-in the GarbageCollector's destructor.

  3. You must not explicitly delete any objects you allocated with ::operator new (size_t, CyberTiggyr::giggle::GarbageCollector &).

  4. Addresses returned by ::operator new (size_t, CyberTiggyr::giggle::GarbageCollector &) must be assigned to a CyberTiggyr::giggle::Ptr$<>$ immediately.

  5. Objects managed by Giggle are safe from destruction only as long as some Ptr$<>$ points to them. So if you get a raw pointer from a Ptr$<>$ and hand it to a function that doesn't know about Giggle, & then you allow the Ptr$<>$ to be destroyed but the other function keeps the raw pointer, you have a problem.9.5

  6. Always ensure that a Ptr$<>$ always holds either NULL or the address of an object allocated with ::operator new (size_t, CyberTiggyr::giggle::GarbageCollector &). A Ptr$<>$ must never, ever hold the address of an object allocated any other way.

  7. Objects under Giggle's control may themselves contain objects under Giggle's control.

Them's the rules.


next up previous contents
Next: The Different Collectors Up: Smart Pointers & Garbage-Collected Previous: Object Creation
Gene Michael Stover
2002-04-28