On Tue, Sep 6, 2016 at 8:08 PM, Esteban Lorenzano <esteba...@gmail.com> wrote: > Hi, > > sorry for arriving so late to this, but I was on holidays :) > this is how autoRelease works: > > 1) #autoRelease of an object registers object for finalisation with a > particular executor. Then behaviour is divided: > > 2.1.1) for ExternalAddresses, it just registers in regular way, who will call > #finalize on GC > 2.1.2) finalize will just call a free assuming ExternalAddress was allocated > (which is a malloc) > > 2.2.1) for all FFIExternalReference, it will register for finalisation what > #resourceData answers (normally, the handle of the object) > 2.2.2) finalisation process will call the object > class>>#finalizeResourceData: method, with the #resourceData result as > parameter > 2.2.3) each kind of external reference can decide how to free that data (by > default is also just freeing). > > An example of this is how CairoFontFace works (or AthensCairoSurface).
At the bottom of FFIExternalResourceExecutor class comment I read... "Note that in #finalizeResourceData: you cannot access any other properties of your instance, since it is already garbage collected." But in my experiments it seems okay to access instance variables in #finalize. For example... CXString >> autoRelease self class finalizationRegistry add: self CXString >> finalize Transcript crShow: 'Finalizing CXString ' ; show: self private_flags. self dispose. Transcript show: ', done!'. CXString >>private_flags "This method was automatically generated" ^handle unsignedLongAt: 5 Libclang getClangVersion autoRelease. Smalltalk garbageCollect. "==> Finalizing CXString 1, done! " Is this an unlucky coincidence? Or maybe something changed from NB to UFFI? (There is a reference to NB there) I am wary of believing my results contrary to the comment. That old engineering principle "When things work, it may be only reinforcing your misconceptions." :) cheers -ben > In you case, you will have something like: > > FFIExternalObject subclass: #CXString > > CXString class>>#finalizeResourceData: version > self ffiCall: #(void clang_disposeString(void *version)) > > notice that here I casted to void*… this is because actually resourceData > answers a pointer, not the object. > > cheers, > Esteban