Tons of lag with more objects

I have a platform game I am building. It has 5 frames. Each frame has physics objects on it. When I goto the next frame, the new scene loads up with new objects. While leaving frame 1, I destroy all the bodies and MC's attached to the bodies in a for loop, and then hit frame 2 and build new bodies and MC's. Problem is, I don't think they are truly destroyed, or are in cache somewhere, because the FPS drops dramatically.

I need the simplest way to completely destroy the world if you will, and have it not sit in cache anywhere, so it goes to garbage collection in AS3. Can I destroy the entire world, and build a new one on each frame? Anyone know the best way about this, or is there a way to destroy everything within the world and have the objects really gone and not sitting around anywhere?

Here is the code I use to destroy the bodies:
Code:
for (var i:int=0; i<testNow.length; i++){
         m_world.DestroyBody(testNow[i]);
         removeChild(testNow2[i]);
         }


testNow and testNow2 are arrays. When I built the bodies, I pushed them into those arrays. testNow = bodies, and testNow2 = movieclips attached to bodies.

I appreciate your time!! Thank you.
If you have any listeners attached to the movieclips they will not be collected. Additionally, if you have references in any other part of your code to those objects then they may not be collected either.
Every single Physics object has an MC attached to it via "bodyDef.userData = MC"

I then use that for loop I talked about to get rid of all the physics objects and their associated MC's. When I destroy and rebuild, the FPS drops at least 15, and then when it happens a third time, it drops another 15. The reason I need to do this is because in the platform game, the player has a few lives, so when the player dies, everything must be reset.

Is there anyway I can simply just destroy the entire world, and make a new world, new objects etc?

Thank you. If I can fix this, I can live happily ever after 😀
The problem is not related to the API. Garbage collection has two ways of cleaning up. The most effective one handles objects that have strong references but that are not linked to any on stage object, but it rarely runs.

If you keep strong references to any object, it will stay in memory, eating up CPU cycles and RAM. You need to get rid of that userdata reference.

Another good practice is not using objects on stage (as in organized per frame) but added as needed and removed as needed. What you are doing, probably will keep the objects on, even if off-stage.

So this isn't related to how Box2D is build up, but rather how the objects that you put on the 5 frames relate to the garbage collection process.
Oh sorry, I actually don't use anything on the stage. I only use classes, to call everything. Now, each MC attached to the box2D are vectorized rather than pixels, but still. It runs perfectly and would if I had 100 levels rather than 5, but the problem lies when I want to get rid of everything and rebuild the entire world. It is like it doubles up, or deletes it but still remains in cache.
Well it isn't the physics I guess. I narrowed it down, and created a scenario where I can build > destroy > rebuild while attaching movieclips to the objects with bodyDef.userData = . It works fine, and the FPS goes back to 50, just where I want it. The movieclips are pixelated rather than vectors in this test, and they also don't have any animations tied to them.

So, after this test, I guess the problem is one of two things. The vector art I am using, which are my movieclips and attached to the physics bodies AND / OR the animations associated with each movieclip are bogging it down.
Whenever you have symbols (movieclips) that only have one frame, export those using Sprite as the Base Class. Sprites are less heavy than MovieClips.

Original thread: https://box2d.org/forum/viewtopic.php?t=4628