10 // The objects inherit from GarbageObject.
11 // The constructor sets users to 0 so the caller must call add_user if it
12 // wants to use it. If it doesn't intend to use it after calling the constructor,
13 // it should not call add_user.
14 // Other users of the object must call add_user to increment the user count
15 // and remove_user to decriment the user count.
16 // The object is only deleted if a call to Garbage::delete_object is made and
17 // the user count is 0.
18 // A user who is using it and wants to delete it must first call
19 // remove_user and then call Garbage::delete_object.
22 // They are deleted by calling delete_object. They get deleted at a
23 // random point later on. The objects must not change anything in their
26 // Can't make graphics elements inherit because they must be deleted
27 // when the window is locked and they change their parent pointers.
29 // Elements of link lists must first be unlinked with remove_pointer and then
30 // passed to delete_object.
32 // ArrayList objects must be deleted one at a time with delete_object.
33 // Then the pointers must be deleted with remove_all.
37 GarbageObject(char *title
);
38 virtual ~GarbageObject();
40 // Called when user begins to use the object.
42 // Called when user is done with the object.
58 // Called by GarbageObject constructor
59 void add_object(GarbageObject
*ptr
);
61 // Called by user to delete the object.
62 // Flags the object for deletion as soon as it has no users.
63 static void delete_object(GarbageObject
*ptr
);
66 // Called by remove_user and delete_object
67 static void remove_expired();
69 ArrayList
<GarbageObject
*> objects
;
71 // Global garbage collector
72 static Garbage
*garbage
;