PyrGC + Finalizer when lib is recompiled

View: New views
2 Messages — Rating Filter:   Alert me  

PyrGC + Finalizer when lib is recompiled

by thelych :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

James 
(or anybody wich already digged into that question or knows a bit about that topic)

i have few questions concerning the use of Finalizer and how they are triggered when the library is recompiled.

It seems that, for PyrObject(s) wich have a Finalizer attached, that the finalizers are not triggered automatically when the lib is recompiled.

For some objects that needs to be finalized properly, because they need to deallocate resources for example, it may results in memory leaks each time the library is recompiled (when there is finalizable PyrObjects left - not marked / or collected yet)

in order to have the finalizer triggered just before the lib is recompiled i added a function member to PyrGC wich calls MajorFlip to the finalizer set then calls ScanFinalizers()

void PyrGC::ForceCollectFinalizers()
{
GCSet *gcs = &mSets[kFinalizerSet];
gcs->MajorFlip();
ScanFinalizers();
}


then calling this at shutdown would trigger the finalizers and correct this behaviour :

gMainVMGlobals->gc->ForceCollectFinalizers();

but i prefer first to ask you :

* is it correct to call it on gMainVMGlobals's GC and make the assumption it won't leave some Finalizer behind ? (althought i did not see any exception to that behaviour until now)
* is it fine to call it on shutdown (either hooking a special primitive at shutdown or coding it directly in shutdownLibrary - example below) ?

void shutdownLibrary();
void shutdownLibrary()
{
closeAllGUIScreens();
aboutToCompileLibrary();
schedStop();
TempoClock_stopAll();
if(gMainVMGlobals && gMainVMGlobals->gc)
gMainVMGlobals->gc->ForceCollectFinalizers();
}


thanks in advance for any answers / tips / confirmation

best,
charles


Re: PyrGC + Finalizer when lib is recompiled

by thelych :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi

here is a new proposition for forcing finalizers to trigger when the lib is recompiled

checks for WHITE and BLACK objs directly
no more use of FlipMajor() + ScanFinalizers() (i experienced some random crashes inside of FlipMajor())

so i decided to directly scan for those objects


void PyrGC::ForceCollectFinalizers()
{
GCSet *gcs = &mSets[kFinalizerSet];
PyrObjectHdr* obj;


//post("checking black finalizers\n");
obj = gcs->mBlack.next;
while( !IsMarker(obj) ) 
{
/*
  post("force_collect obj (%p) class (%s) color: (%s)\n", obj, obj->classptr->name.us->name, 
IsBlack(obj) ? "black" : (IsWhite(obj) ? "white" : (IsGrey(obj) ? "grey" : "free"))
);
  */
Finalize((PyrObject*)obj);
obj = obj->next;
}


//post("checking white finalizers\n");
obj = gcs->mWhite.next;
while( !IsMarker(obj) ) 
{
/*
post("force_collect obj (%p) class (%s) color: (%s)\n", obj, obj->classptr->name.us->name, 
IsBlack(obj) ? "black" : (IsWhite(obj) ? "white" : (IsGrey(obj) ? "grey" : "free"))
);
*/
Finalize((PyrObject*)obj);
obj = obj->next;
}
}


still testing...

any comments greatly appreciated (Mr JMC ? Ryan ? anybody ?)

seems like a cold lonely place :(

best,
charles


Le 15 avr. 09 à 13:28, thelych@... a écrit :

Hi,

James 
(or anybody wich already digged into that question or knows a bit about that topic)

i have few questions concerning the use of Finalizer and how they are triggered when the library is recompiled.

It seems that, for PyrObject(s) wich have a Finalizer attached, that the finalizers are not triggered automatically when the lib is recompiled.

For some objects that needs to be finalized properly, because they need to deallocate resources for example, it may results in memory leaks each time the library is recompiled (when there is finalizable PyrObjects left - not marked / or collected yet)

in order to have the finalizer triggered just before the lib is recompiled i added a function member to PyrGC wich calls MajorFlip to the finalizer set then calls ScanFinalizers()

void PyrGC::ForceCollectFinalizers()
{
GCSet *gcs = &mSets[kFinalizerSet];
gcs->MajorFlip();
ScanFinalizers();
}


then calling this at shutdown would trigger the finalizers and correct this behaviour :

gMainVMGlobals->gc->ForceCollectFinalizers();

but i prefer first to ask you :

* is it correct to call it on gMainVMGlobals's GC and make the assumption it won't leave some Finalizer behind ? (althought i did not see any exception to that behaviour until now)
* is it fine to call it on shutdown (either hooking a special primitive at shutdown or coding it directly in shutdownLibrary - example below) ?

void shutdownLibrary();
void shutdownLibrary()
{
closeAllGUIScreens();
aboutToCompileLibrary();
schedStop();
TempoClock_stopAll();
if(gMainVMGlobals && gMainVMGlobals->gc)
gMainVMGlobals->gc->ForceCollectFinalizers();
}


thanks in advance for any answers / tips / confirmation

best,
charles