Comments (3)
Good question!
So, when you create a constraint you assign it to two bodies, like j = pymunk.PinJoint(body1, body2)
. At this point the constraint object will keep a reference to the bodies (this is not exposed in the API). For convenience its also possible to get the constraint(s) out from the body, with body.constraints
as you write. If the constraint is not needed anymore and all references to it are deleted, then the reference between the constraint and body will also be cleaned up eventually (behind the scenes its implemented as a weakset, so this cleanup depends on the garbage collector).
>>> import pymunk
>>> b1 = pymunk.Body()
>>> b2 = pymunk.Body()
>>> j = pymunk.PinJoint(b1, b2)
>>> b1.constraints
{<pymunk.constraints.PinJoint object at 0x0000019DAC940F50>}
>>> del j
... some other code that triggers garbage collection
>>> b1.constraints
set()
Note that the space is not involved here. The constraint - body reference can exist outside the space. (but of course, the constraint wont be cleaned up while the constraint and body are in the space since the space will keep a reference to the constraint)
from pymunk.
Hello,
Thank you for the detailed explanation. This clarifies how constraints are managed in Pymunk, and why the constraints remain in body.constraints even though they have been removed from the space. I will take your advice and ensure all references to constraints are removed when they are no longer needed.
from pymunk.
Great! I made a small improvement to the docs as well.
from pymunk.
Related Issues (20)
- Moving too fast leads to a series of problems such as through walls HOT 1
- How to create a customized joint? HOT 13
- c
- Memory leak with cpSpaceGetBodyPositions? HOT 11
- Body.copy() raising AttributeError HOT 2
- Add constraint between two static bodies which are later changed to dynamic does not work HOT 1
- Batch module HOT 3
- Body.copy() with multiple shapes attached to a body HOT 4
- The collision between two segments HOT 6
- Can not set max_force od pymunk.constraints.DampedRotarySpring HOT 9
- Faster way for getting Polygon vertices in world coordinates HOT 3
- Batch api for applying impulse HOT 9
- How to get the net force from a set of collisions HOT 4
- `Space` may wrongly get unlocked during `step()` HOT 2
- RuntimeError when using `.remove()` in `separate` in very uncommon circumstances HOT 8
- lack of a method to create an aproximated disk (polygon) HOT 5
- Segmentation fault when setting `body_type` to dynamic HOT 1
- Body.sleep doesn't seem to work properly HOT 4
- Different segment orientations cause BB.segment_query to return different results
- How is ContactPoint.distance calculated? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pymunk.