2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
9 #include <proto/exec.h>
10 #include "intuition_intern.h"
12 /*****************************************************************************
15 #include <intuition/classes.h>
16 #include <proto/intuition.h>
18 AROS_LH1(BOOL
, FreeClass
,
21 AROS_LHA(struct IClass
*, iclass
, A0
),
24 struct IntuitionBase
*, IntuitionBase
, 119, Intuition
)
27 Only for class implementatores.
29 Tries to free a class which has been created with MakeClass() in the
30 first place. This will not succeed in all cases: Classes which
31 still have living objects or which are still beeing used by subclasses
32 can't simply be freed. In this case this call will fail.
34 Public classes will always be removed with RemoveClass() no matter
35 if FreeClass() would succeed or not. This gurantees that after the
36 call to FreeClass() no new objects can be created.
38 If you have a pointer to allocated memory in cl_UserData, you must
39 make a copy of that pointer, call FreeClass() and if the call
40 succeeded, you may free the memory. If you don't follow these rules,
41 you might end up with a class which is partially freed.
44 iclass - The pointer you got from MakeClass().
47 FALSE if the class couldn't be freed at this time. This can happen
48 either if there are still objects from this class or if the class
49 is used a SuperClass of at least another class.
51 TRUE if the class could be freed. You must not use iclass after
55 *Always* calls RemoveClass().
58 // Free a public class with dynamic memory in cl_UserD
60 int freeMyClass (Class * cl)
62 struct MyPerClassData * mpcd;
64 mpcd = (struct MyPerClassData *)cl->cl_UserData;
68 FreeMem (mpcd, sizeof (struct MyPerClassData));
80 MakeClass(), "Basic Object-Oriented Programming System for Intuition"
81 and "boopsi Class Reference" Dokument.
83 *****************************************************************************/
89 SANITY_CHECKR(iclass
,FALSE
)
91 ObtainSemaphore(&GetPrivIBase(IntuitionBase
)->ClassListLock
);
94 Make sure no one creates another object from this class. For private
95 classes, this call does nothing.
99 if (iclass
->cl_SubclassCount
== 0 && iclass
->cl_ObjectCount
== 0)
101 AROS_ATOMIC_DEC(iclass
->cl_Super
->cl_SubclassCount
);
103 DeletePool(iclass
->cl_MemoryPool
);
104 FreeMem(iclass
, sizeof(Class
));
109 ReleaseSemaphore(&GetPrivIBase(IntuitionBase
)->ClassListLock
);