Properly destroying components created with set_ref

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
jyoung
Posts: 694
Joined: Thu Jan 21, 2016 6:43 am
Location: Oklahoma City, OK USA

Properly destroying components created with set_ref

Post by jyoung »

Is there a "proper" way to destroy components that were created with set_ref?

I am managing the lifetime of objects that inherit from CMGRPTReportList where the object is defined like:

Code: Select all

define_com class(#CMGRPTReportList) name(#ReportList) reference(*DYNAMIC)
uTerminate and uInitialize are mthroutines defined in CMGRPTReportList that provides the object a place to get initialized and clean up before getting killed.

When I create a new object and kill the current object I am doing this: (STD_TEXT contains the identifier of the object to be created)

Code: Select all

#STD_TEXT := #ReportListMap<#reportId>

if (#ReportList *IsNot *NULL)
#ReportList.uTerminate
set_ref com(#ReportList) to(*NULL)
endif

set_ref com(#ReportList) to(*CREATE_FROM #STD_TEXT)

if (#ReportList *IsNot *NULL)
#ListLayoutItem.Manage <= #ReportList
#ListLayoutItem.Sizing := FitBoth
#ReportList.Parent <= #ListPanel
#ReportList.uInitialize
endif
Is setting the object to *NULL the correct way to handle destroying the object?
MarkD
Posts: 692
Joined: Wed Dec 02, 2015 9:56 am

Re: Properly destroying components created with set_ref

Post by MarkD »

That looks good to me.
If there are no references to #ReportList left anywhere it should get destroyed.
You can make sure by testing with a temporary #Com_Owner.DestroyInstance event handler in #ReportList with a message box.
If that event fires then you are sure that it got destroyed.
User avatar
Stewart Marshall
Posts: 417
Joined: Thu Nov 05, 2015 5:25 pm

Re: Properly destroying components created with set_ref

Post by Stewart Marshall »

Here's a more in depth look at resource handling in VL.

Regards
Attachments
Tracking VL Objects and Resource Consumption.doc
(323.5 KiB) Downloaded 986 times
Stewart Marshall

Independent IT Consultant
www.marshallfloyd.com.au
User avatar
Stewart Marshall
Posts: 417
Joined: Thu Nov 05, 2015 5:25 pm

Re: Properly destroying components created with set_ref

Post by Stewart Marshall »

Source code for the examples in the previous document

Regards
Attachments
ManagingResources.zip
(17.73 KiB) Downloaded 987 times
Stewart Marshall

Independent IT Consultant
www.marshallfloyd.com.au
Post Reply