Object instances are memory constructs that can be located in different places. Usually they are instantiated as standalone entities and their lifecycle are determined by the “New” and “Destroy” macro invocations.
Less obvious are object instances created by resources, better said as part of i.e. a resource dialog. In this case, ObjAsm limit their lifecycle between the WM_NCCREATE and WM_NCDESTROY messages sent to those objects.
Objects instances can also be created on stack memory, like variables within a method or procedure that are created with the “local” keyword. The necessary stack space to hold the object instance is reserved automatically by the prologue code at virtually no CPU cost. Since the instance memory is freed by the epilogue code when the method or procedure finished , it is not necessary to call the Destroy macro.
The prologue code simply reserves the necessary amount of stack memory, but does not initialize it. This is the responsibility of the New macro when it is called in this context. Usually it follows the constructor method to initialize additional resources. Before the instance memory is released, the destructor must be called to free the previously allocated resources!
OCall Object1::MyObject.Init, 120
An object can be nested with the Embed macro into another object. This case is different from a local object because the nested object stays alive with its host that controls its initialization and finalization. A nested object should never be freed with the Destroy macro.
Object MyApp,, Primer
Embed SBar, StatusBar
For a more flexible use of the method invoking, the OCall macro can accept as first parameter an instance pointer or a symbol of the local or nested object. In this last case, the instance pointer is calculated in the most efficient way.