Maya unloads a plugin but doesn't free the library


#1

I have my .mll plugin file. I load it and unload it, e.g. using the plugin manager. For some reason maya doesn’t call the FreeLibrary and the .mll remains loaded in memory (even when the plugin manager shows an unticked checkbox). Then, in order to build a new version of the plugin (that replaces the file), I need to kill maya. It just started to happen without any significant change to the code or the system. Any ideas?


#2

To bypass the problem, I’m calling the following pre-link.bat in the pre-link event in VS:

commandPort.exe file -f -new; unloadPlugin "SpaceDeformation2D.mll";
echo commandPort.exe file -f -new; unloadPlugin "SpaceDeformation2D.mll";
sleep .1
if exist "C:\prj\plug-ins\SpaceDeformation2D.mll" rm "C:\prj\plug-ins\SpaceDeformation2D.mll"
sleep .1

where rm is from cygwin.


#3

No ideas from me sorry. But I’m interested in knowing too. Zoharl,did this start happening after applying a service pack? I know you said “no significant change”, but I thought I’d check anyway.

David


#4

I usually don’t apply service packs since they fix one thing and break another (so no, I didn’t install anything new). If this still bothered me, I would have tried the latest service pack. I just thought to share my solution (which is surprising that rm can delete this locked dll).


#5

Cygwin rm doesn’t delete a file if it’s in use, it just moves it to the recycle bin. I don’t know what happens if the recycle bin is disabled.


#6

If it moved the file to the recycle bin, then it would have explained how it deletes a file that is supposedly locked. But my recycle bin is enabled, and rm doesn’t move files to it.


#7

Does the uninitialize function really uninitialize everything that got initialized? That happened to me and I got a behaviour what you describe,.


#8

in my case, all I would need is to close the file before unload, but I can see you’re already doing that.

In all other cases it would be errors in my own code - e.g., not releasing resources in uninitializePlugin().

Try ruling out external configuration: checkout previous version of code and see if that properly loads/unlloads. Then you’ll know if that’s an issue with code change or Maya configuration.


#9

The code is here, if you want to look further.

https://cygwin.com/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=winsup/cygwin/syscalls.cc;h=4b494419a0c3e10d62537fe3e9cac6d807401e09;hb=master#l768


#10

Not sure about ‘uninitialize everything that got initialized’. I do try to free allocated resources (usually I work with STL, and it’s done automatically in the destructor). But I don’t recall that any of that should prevent WINAPI call for FreeLibrary. In fact, it should the OS should automatically release all allocations leftovers. Also, if there’s a problem in the unloading of the plugin, I would have expected Maya to tell me something about it, but the plugin manager just unchecks the plugin checkbox as usual.

I think last time I tried to look into this, I simply load and unload the plugin without doing anything in the initialization, and the problem still persisted. But I’ll need to verify that. I’m not really spending time on this, since my rm workaround works fine. Also, the problem is inconsistent - sometimes happens sometimes not; a long time ago I gave up on fighting with Maya and found that coming up with workarounds requires less time.

I see in the cygwin code a check for a recycle bin, but I’m not sure I’ll go into it to check why it behaves differently on my system :slight_smile:


#11

With “Uninitialieze everything” I meant that for every command/node/whatever you initialize you have a proper uninitialize call. I have no idea what you are doing in your initialize function so it was just a shot in the dark…