lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Test case (use any dlls in place of dll1.dll and dll2.dll; I just made
two stub dlls in Delphi):

require 'alien'

local dll1,dll2='dll1.dll','dll2.dll'
local libs = setmetatable({}, {__mode='k'})
local lib

lib = alien.load(dll1)
libs[lib] = true
lib = alien.load(dll2)
libs[lib] = true

local count,collect='count','collect'
print(collectgarbage(count)*1024)
alien.loaded[dll1] = nil
alien.loaded[dll2] = nil
assert(not next(alien.loaded))
collectgarbage()
print(collectgarbage(count)*1024)
print(next(libs) and 'libs still hanging:' or 'all libs garbage-collected')
for lib in pairs(libs) do
	print('',lib)
end


The above prints:

>lua "test_dll.lua"
48570
42609
libs still hanging:
	alien library ˆ"A
	alien library dll2.dll
>Exit code: 1    Time: 0.216



On Fri, Sep 24, 2010 at 04:22, Fabio Mascarenhas <mascarenhas@acm.org> wrote:
> Imported functions do not keep a backlink to the libraries they come
> from, so libraries would get unloaded while you still keep references
> to their functions. I didn't consider unloading libraries as a
> priority, so didn't include this backlink. The loaded table does
> double duty as a way to keep library objects alive and as a cache to
> keep from searching for the library more than once.
>
> Forcing the unloading of a library the way you are doing should not
> cause problems if you keep from calling any function from that
> library, though. Can you show an example of the code that is causing
> problems?
>
> --
> Fabio Mascarenhas
>
>
> On Thu, Sep 23, 2010 at 10:02 PM, Cosmin Apreutesei
> <cosmin.apreutesei@gmail.com> wrote:
>> Hi,
>>
>> I was wondering if anyone knows if there's a good reason for alien to
>> keep a reference to all libraries it loads (in alient.loaded) from
>> garbage collecting.
>>
>> The reason I ask is because I sometimes get buffer overruns and such
>> if I try to unload a library by means of alien.loaded[libname] = nil;
>> garbagecollect('collect'). Is there a known problem with this
>> approach?
>>
>> Thanks,
>> Cosmin.
>>
>>
>
>