New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory management tests fail #199
Comments
I am wondering, how the Handle mechanism works from within python. What looks strange to me, is that GetHandle just casts a raw pointer. I don't know the internals, but Handles are reference counted. In C++
creates a pointer and a handle, that guards this pointer. Also it increases the refcount of the transient object. Pythonocc does things like
which just casts a Transient pointer address to a Handle pointer. Does this suffice to increase the refcount of the Transient object? @tpaviot Can you please share the ideas behind your handle implementation. |
@rainman110 Yes, this implementation is enough to increase reference counting of the transient object. Try this: $ python
>>> from OCC.Standard import *
>>> MyTransient = Standard_Transient()
>>> MyTransient.GetRefCount()
0
>>> Handle_MyTransient = MyTransient.GetHandle()
>>> MyTransient.GetRefCount()
1
>>> Handle_MyTransient2 = MyTransient.GetHandle()
>>> MyTransient.GetRefCount()
2 |
The Nullify method decreases reference counting:
|
Tests above are launched on win32/py27 |
Note that the memory results should depend on the value of the MMGT_OPT en var. |
My windows / python3.5 test was done on win64. Look at this example: In [1]: from OCC.Standard import *
In [2]: MyTransient = Standard_Transient()
In [3]: MyTransient.GetRefCount()
Out[3]: 0
In [4]: Handle_MyTransient = MyTransient.GetHandle()
In [5]: MyTransient.GetRefCount()
Out[5]: 1
In [6]: Handle_MyTransient.Nullify()
In [7]: MyTransient.GetRefCount()
Out[7]: 69891209 Isn't this strange. Happens only on windows py35. The question is, what happens under the hood. It also happens only, if MMGT_OPT=0. If MMGT_OPT==1, then the last refcount is zero as expected. |
In the swig generated shadow classes, the GarbageCollector module is never imported! Therefore it does not get called. The thrown exception will be ignored by except:
pass |
@rainman110 right |
I can't remember where its was imported and when/why it was removed ... |
Fixed by PR #200 |
If i run core_memory_unitttest.py, I get many errors:
Did this work in the past?
The text was updated successfully, but these errors were encountered: