Andrew,
     you're quite correct.  It was definitely failing without this 
change and working with it but the change was the wrong approach. I've 
added a 'plugin->grab()' call to the CppTPGDescriptorWrapper constructor 
so that the reference count is increased.  Correspondingly, I've added a 
plugin->release() call to the destructor of the CppTPGDescriptorWrapper 
class.  This works fine now.

     I've merged the change into cam-py on my GitHub repository but I 
can't issue another pull request until the one you're processing now is 
either rejected or accepted.

     Ta
     David Nicholls

On 19/06/2013 4:47 PM, Andrew Robinson wrote:
>
> In src/Mod/Cam2/App/TPG/CppTPGFactory.cpp:
>
> > @@ -61,6 +66,11 @@ void CppTPGFactoryInst::scanPlugins()
> >  	QString path = QString::fromAscii(App::GetApplication().Config()["AppHomePath"].c_str());
> >  	path.append(QString::fromAscii("Mod/Cam/CppTPG/"));
> >
> > +	/*
> > +	// NOTE: We cannot delete the plugins here because pointers to them are still held by
> > +	// parent objects (CppTPGDescriptorWrapper).  As an alternative, we're going to check each file by name and only
> > +	// load those that we have not previously seen.
> > +
>
> Was this actually causing issues? The Plugins, CPPTPG's and 
> TPGDescriptor objects are all participating in 'reference counting'. 
> I.e. the 'release()' method is just saying "I don't need this object 
> anymore" and it checks the reference count and only deletes the object 
> if it was the last to be using it. The CppTPGDescriptorWrapper class 
> that also references this plugin /should/ still own a reference to 
> this plugin so it wont actually be deleted until its done with it.
>
> Check out the 3rd figure in the "CppPlugin architecture" section of 
> the design document; it describes the dependencies of the reference 
> counting classes.
>
> The reason all objects are being released here and re-opened again 
> later is so that the User (a TPG Dev) can reload the DLL/SO file to 
> get a new version of the TPG without restarting FreeCAD. This feature 
> isn't complete yet but I would like to keep that within the design.
>
> —
> Reply to this email directly or view it on GitHub 
> <https://github.com/andrewjrobinson/FreeCAD_sf_master/pull/5/files#r4766356>.
>