PhisicsMagnetBehavior and Garbage Collection

Dec 5, 2010 at 10:02 PM

Hi All,

 

Great Library, I have been using it for several weeks now and I’m delighted with it. I may write an blog article on the PhisicsMagnetBehavior because you can really achieve a lot of fun effects with it. I added a group id to the behavior and modified the force caculation to only include shapes with the same group id. However, I’ve run into several issues durring WP7 development.

First, in the PhisicsMagnetBehavior Class I modified the controller_TimerLoop because it was referencing the other.sprite.BodyObject.Position in the force calculation.

 Vector2 force = other.sprite.BodyObject.Position - this.BodyObject.Position;

 To

 Vector2 force = other.sprite.Position - this.sprite.Position;

 

 

Second, in the PhisicsMagnetBehavior Class I made the PhysicsMagnetBehavior.worldMagnets List public because it does not get wiped when the PhysicsControlerMain Class is initialized. This way I could clear it, otherwise I would end up with multiple references to same object (effectively doubling the force between engine initializations, I think).

 public static List<PhysicsMagnetBehavior> WorldMagnets

       {

           get { return PhysicsMagnetBehavior.worldMagnets; }

           set { PhysicsMagnetBehavior.worldMagnets = value; }

       }

 

Third, there seems to be some major memory leaks that is visible after page transitions. I’ll try to track these down using Weak References. I used dnp.Counters to verify that the memory is not be reallocated by the GC. I created a simple demo project with two pages each containing a PhysicsControlerMain behavior and a button to switch between them. The PhysicsControler canvas contains about 250 rectangles and on each page transition memory usage continues to grow by a regular amount.  Any help or suggestions about this matter would be greatly appreciated.

 

Thanks,

Matt

Dec 8, 2010 at 12:38 AM

Hi All,

Just an update, I resolved the memmory issues by destroying all the event handlers in the physics behaviors durring the page naviagting event and destroying all the objects in the physics control body object dictionary.

Thanks,

Matt