Garbage generated during add & collisions

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
sqrtpi
Posts: 9
Joined: Tue Nov 22, 2011 12:10 am

Garbage generated during add & collisions

Post by sqrtpi »

Hi, is it normal for a few kilobytes of heap memory to be allocated when:
  • adding an object (entity) to the space?
  • collisions occur in the space ?
  • calling UpdateBoundingBox ?
if so, is there any alternative ways to perform the above without generating garbage?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Garbage generated during add & collisions

Post by Norbo »

adding an object (entity) to the space?
Adding an object to the space could force expansion of various lists or data structures. The majority of the allocated space is not garbage; any garbage is just caused by old arrays that were thrown out after a resizing.
collisions occur in the space ?
If the collision pairs exceed the pooled set of pairs, more will be created. When they are returned, the pool lists may need a resize, which can cause a little garbage. You can pre-pool however many you want by setting the capacities on relevant NarrowPhaseHelper.Factories.
calling UpdateBoundingBox ?
UpdateBoundingBox should not cause garbage nor allocate on the heap. It is called every frame by every entity.

The important thing to note in the first two cases is that most allocated heap data is necessary, not garbage, and will not be subject to garbage collections. The actual garbage caused by simulation expansion is small, basically one-time, and can be handled up front in most cases.

If you encounter a scenario with excessive or anomalous garbage, I can take a closer look. CLR profiling results or a reproduction case would be helpful in diagnosing possible problems.
sqrtpi
Posts: 9
Joined: Tue Nov 22, 2011 12:10 am

Re: Garbage generated during add & collisions

Post by sqrtpi »

thanks, that makes sense. based on your explanation, the allocated memory I'm seeing during profiling seems normal (a test case where several hundred objects are added with a few hundred collisions)
Post Reply