From: Kris T. <kri...@gm...> - 2014-06-28 12:54:18
|
Hi all I've looked a bit more into the crashes which I get when exiting matlab after creating some objects. I also get them when using "clear all" in matlab. I don't seem to have any problems when first doing "clear" in matlab. It seems what's happening is that without the initial "clear", objects get deleted which no longer exist. A similar issue has been discussed on http://www.mathworks.com/matlabcentral/newsreader/view_thread/278243 the recommendation in that thread is to add "mexLock" and "mexUnlock" calls. Whenever you call mexLock(), it increments an internal counter, which gets decremented with mexUnlock. So, presumably this means that the mex file doesn't get unloaded before all objects are deleted. I'm not 100% sure that this would solve my problem, but we do seem to need it in any case. However, I don't really know how to implement it. It's easy enough to add a mexLock() call to SWIG_Matlab_NewPointerObj, but we need to make sure that there's a corresponding number of mexUnlock() calls of course. It has to be in the same mex file and currently we don't have control over what ends up in the "delete" wrappers. Maybe a trick is to add a delete method to SwigRef, which then goes and calls a delete in the mex file (but currently SwigRef doesn't need to know about the mex file). Alternatively, I guess we could a class_handler base-class as in http://www.mathworks.com/matlabcentral/fileexchange/38964 (which summarises the recommendations of the above thread). Any ideas? Until we solve this problem, remember to do a "clear" in matlab. Kris |