Disposing of window object and linked objects

3 posts / 0 new
Last post
jwanderson88
jwanderson88's picture
Offline
Last seen: 2 years 1 month ago
Joined: 2019-04-13 19:29
Disposing of window object and linked objects

In the following example, if you do a dispose object of the window (objects[ST_WINDOW]), does it also dispose of the MsgPort, winAppPort, and List, selectmode, or do you have to free them separately with FreeSysObject(). (Sorry, I know this is messy.)

WORD radiodata;

struct MsgPort *winAppPort;
winAppPort = (struct MsgPort *)IExec->AllocSysObject(ASOT_PORT, NULL);
struct List *selectmode;
selectmode = (struct List *)IExec->AllocSysObject(ASOT_LIST, NULL);
IExec->NewList(selectmode);
IExec->AddTail(selectmode, IRadioButton->AllocRadioButtonNode(1,
RBNA_Label, "Difference",
TAG_DONE));
IExec->AddTail(selectmode, IRadioButton->AllocRadioButtonNode(1,
RBNA_Label, "Copy",
TAG_DONE));

objects[ST_WINDOW] = IIntuition->NewObject(WindowClass, NULL,
WA_Title, "Simple Window",
WA_DragBar, TRUE,
WA_CloseGadget, TRUE,
WA_SizeGadget, TRUE,
WA_DragBar, TRUE,
WA_DepthGadget, TRUE,
WA_Activate, TRUE,
WA_NewLookMenus, TRUE,
WINDOW_IconifyGadget, TRUE,
WINDOW_Position, WPOS_CENTERSCREEN,
WINDOW_AppPort, winAppPort,
WINDOW_Layout, (Object*)IIntuition->NewObject(LayoutClass, NULL,
LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
LAYOUT_AddChild, (Object*)IIntuition->NewObject(LayoutClass, NULL,
LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
LAYOUT_AddChild, objects[ST_SELECT] = IIntuition->NewObject(RadioButtonClass, NULL,
GA_ID, ST_SELECT,
GA_RelVerify, TRUE,
RADIOBUTTON_Spacing, 10,
RADIOBUTTON_Labels, selectmode,
RADIOBUTTON_Selected, &radiodata,
TAG_END),
LAYOUT_AddChild, (Object*)IIntuition->NewObject(LayoutClass, NULL,
LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
LAYOUT_AddChild, objects[ST_DIRA] = (Object *)IIntuition->NewObject(StringClass, NULL,
GA_ID, ST_DIRA,
GA_RelVerify, TRUE,
STRINGA_MinVisible, 50,
TAG_END),
LAYOUT_AddChild, objects[ST_DIRB] = (Object *)IIntuition->NewObject(StringClass, NULL,
GA_ID, ST_DIRB,
GA_RelVerify, TRUE,
STRINGA_MinVisible, 50,
TAG_END),
TAG_END),
LAYOUT_TopSpacing, 20,
LAYOUT_BottomSpacing, 20,
//LAYOUT_LeftSpacing, 20,
//LAYOUT_RightSpacing, 20,
//LAYOUT_InnerSpacing, 20,
//LAYOUT_SpaceOuter, TRUE,
//LAYOUT_SpaceInner, TRUE,
TAG_END),
LAYOUT_AddChild, (Object*)IIntuition->NewObject(LayoutClass, NULL,
LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
//LAYOUT_InnerSpacing, 50,
LAYOUT_AddChild, objects[ST_OK] = IIntuition->NewObject(ButtonClass, NULL,
GA_ID, ST_OK,
GA_RelVerify, TRUE,
GA_Text, "OK",
TAG_END),
CHILD_MaxWidth, 100,
LAYOUT_AddChild, objects[ST_CANCEL] = IIntuition->NewObject(ButtonClass, NULL,
GA_ID, ST_CANCEL,
GA_RelVerify, TRUE,
GA_Text, "Cancel",
TAG_END),
CHILD_MaxWidth, 100,
TAG_END),
TAG_END),
TAG_END);

jabirulo
jabirulo's picture
Offline
Last seen: 1 month 2 weeks ago
Joined: 2013-05-30 00:53
Re: Disposing of window object and linked objects

AFAIK if you do some "Alloc*" you need to "Free*" them.
AllocSysObject autodoc says:
...
NOTES
ALWAYS FREE YOUR RESOURCES!! Even though the resources will be tracked
and deleted, this is *only* a method to get rid of the program's resources
when the program crashes or exits unexpectedly. DO NOT RELY ON THIS
MECHANISM. It's for emergency cases only.

SEE ALSO
FreeSysObject(),

AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P

broadblues
broadblues's picture
Offline
Last seen: 4 years 10 months ago
Joined: 2012-05-02 21:48
Re: Disposing of window object and linked objects

window.class will dispose of the attched gadgets, but not things like msgports. It can't dispose of those as it doesn't know how they were allocated, so if you allocated them yourself you must free them too.

The list attached to the radiobutton gadget must also be disposed of yourself. Remove it from the radio button gadget before freeing the nodes then the list object.

Log in or register to post comments