Re: FreeLibrary()

new topic     » goto parent     » topic index » view thread      » older message » newer message
jimcbrown said...
eukat said...


I ran a tiny app for loading and unloading a dll 10k times, to time it, and found a memory leak. The app is at http://openeuphoria.org/pastey/153.wc , there's a short pause at the end of the first loop to catch the memory use total, and then the any_key() at the end to see the final memory use. First run uses ~10 megabytes, but use grows to ~100 megabytes after 10k runs. It's keeping ~9k of ram for each loop thru the load-unload loop. The dll source is at http://openeuphoria.org/pastey/154.wc .



eukat

Part of this is due to the internals of define_c_func/proc. Everytime define_c_func/proc is called, a wrapper is made of the raw function pointer along with extra info (like the parameters and return type), and then a "C routine id" is returned.

Since you use the w32api to unload the shared object,


I am open to using other methods, if you know of one, show me it working, please.

jimcbrown said...

the backend/runtime doesn't know that the shared object has been unloaded and keeps those wrappers around, wasting memory. AFAIK there's no way to free that memory short of ending the entire program.


If the back end creates those wrappers on demand, then the back end should have a named pointer to them, so an unload operation by that name should make that memory available for the next load(open_dll) operation. In this case, i am performing the loop on a DLL of the same name, it's not even like i am changing name, or DLL size, or number of functions in the DLL, or etc etc..

jimcbrown said...

9 kilobytes for a single define_c_func() call seems excessive, though. I was expecting more like 10 bytes or something (which times a million would only take up under 10 megabytes). Hopefully Matt can shed some light on this.


I agree. Granted the OS prolly cached the whole operation, since i didn't change up the DLL i loaded, but swapping in-out 500 DLLs per second is impressive, i think.

useless

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu