Hello,

I'm using nim to make a dynamic link library (dll) to be used by a python 
program on Windows, and having a trouble.

I want to reuse the nim program, and I have to use not `ptr object` type but 
`ref object` type it will be managed by GC.

(below is an example to the last.)
    
    
    type
      Hoge = ref object
        val: int
    
    var hoge: Hoge
    
    
    Run

The python program call the dll's functions many time and `hoge` has to be 
constructed then.

In the python program, a memory shortage problem is occurred. I think it is 
caused because the dll doesn't free the memory.
    
    
    Traceback (most recent call last):
      ...
    OSError: exception: access violation writing ...
    
    
    Run

So I tried the below code it is run at the end of the function so that GC 
collects `hoge` object.
    
    
    hoge = nil
    
    
    Run

but there are no improvement...

There are a possibility that the cause isn't the memory occupied by dll, but 
please leave that aside for now.

I want to know two points below:

  * Is `hoge` object freed by above code ?
  * If not, what is the equivalent code to `deallocate hoge` (`hoge` is `ptr 
object`) for `ref object`?



# environment

  * nim version : 0.18.0 [Windows: amd64]



Compiling is executed by the below code:
    
    
    nim c --app:lib test.nim
    
    
    Run

and functions which will be called by the python program have the below pragma:
    
    
    {.cdecl, exportc, dynlib.}
    
    
    Run

I'm Japanese so when my English is strange please excuse me. If you know 
anything about this, Could you give me your advice?

Thank you.

Reply via email to