Skip to content
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

Closed
rainman110 opened this issue Jan 13, 2016 · 10 comments
Closed

Memory management tests fail #199

rainman110 opened this issue Jan 13, 2016 · 10 comments

Comments

@rainman110
Copy link
Collaborator

If i run core_memory_unitttest.py, I get many errors:

Under linux python 2 + 3.4: Two errors (testCollector, testGC)
Under windows / python 3.5: Same 2 errors + failure of testNullifyHandle
Under windows / python 3.4: Same 2 error as under linux

Did this work in the past?

@rainman110
Copy link
Collaborator Author

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++

Handle_MyTransient h = new MyTransient()

creates a pointer and a handle, that guards this pointer. Also it increases the refcount of the transient object.

Pythonocc does things like

(Handle_MySelf*) &SelfPointer

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.

@tpaviot
Copy link
Owner

tpaviot commented Jan 13, 2016

@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

@tpaviot
Copy link
Owner

tpaviot commented Jan 13, 2016

The Nullify method decreases reference counting:

>>> Handle_MyTransient.Nullify()
>>> MyTransient.GetRefCount()
1

@tpaviot
Copy link
Owner

tpaviot commented Jan 13, 2016

Tests above are launched on win32/py27

@tpaviot
Copy link
Owner

tpaviot commented Jan 13, 2016

Note that the memory results should depend on the value of the MMGT_OPT en var.

@rainman110
Copy link
Collaborator Author

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.

@rainman110
Copy link
Collaborator Author

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

@tpaviot
Copy link
Owner

tpaviot commented Jan 13, 2016

@rainman110 right

@tpaviot
Copy link
Owner

tpaviot commented Jan 13, 2016

I can't remember where its was imported and when/why it was removed ...

@tpaviot
Copy link
Owner

tpaviot commented Jan 22, 2016

Fixed by PR #200

@tpaviot tpaviot closed this as completed Jan 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants