AS3 Port: userData doesn't seem to be released properly.

No one else has noticed this, but that's because no one has really looked in the flash port.

Perhaps I've misunderstood, but I saw no evidence that the body was being cleaned up but no the actor. DestroyBody doesn't promise to release all references (as it get's its contract from C++ where this is a non-issue). My presumtion was that references could be left via a chain like

my_world->m_pairManager->m_freePairsList->next->...->next->body->userData.

(or similarly for proxies). I'd check this code if you are concerned, but first just use the debugger to see if bodies are getting cleaned up or not. Sounds like the Java port is more robustly written and actually sets next->body=null;.

But as you create new pairs (or proxies) it will eventually re-use the old ones, and then the actor will be released. So there's no unbounded growth of non-collected data.
BorisTheBrave wrote:
My presumtion was that references could be left via a chain like

my_world->m_pairManager->m_freePairsList->next->...->next->body->userData.

(or similarly for proxies). I'd check this code if you are concerned, but first just use the debugger to see if bodies are getting cleaned up or not. Sounds like the Java port is more robustly written and actually sets next->body=null;.

That could be. I don't think we did anything special in the Java port, apart from porting the C++ as closely as possible (which, for that bit of code, was actually quite difficult because of some serious pointer-fu).

Taking a quick look through the AS3, I see that the b2PairManager.removePair(b2Proxy,b2Proxy) function is significantly simpler than the JBox2d one, but that may be because the AS3 pair manager is simpler itself, I'm not sure.

I'm not even positive that JBox2d releases bodies correctly, to be honest, as I've never checked in detail. As you've mentioned, the fact that the capacities are limited and entries recycled means that in the long run the growth should be bounded, barring other issues.
This isn't an issue C++ deals with, so you won't have inherited the solution from that.
And the AS3 port has a different pair manager, which I wrote to get rid of the proxy and pair limits, and take advantage of the built in objects.

Also, I've checked the code now, and in AS3 both pairs and proxies set userData=NULL before putting them in the recycle pool. So I don't know what's wrong.
I doubt any of this will apply to the AS3 port, but for the Python port dealing with userData had all sorts of quirks that needed to be worked out, including not being released properly. I'm certain it's for different reasons, as you aren't dealing with interfacing one language from another in AS3 like in Python. But in any case, here's what had to be done:

To allow for proper garbage collection, it's necessary to increase the reference count of the userData upon creating the body/shape (as the userData reference is copied from the definition to the actual body/shape), and decrease it when the body/shape itself was deleted. When the definitions are destructed, the userData of course needed to be cleared/reference count decreased. In DestroyBody/Shape, the reference count is again decreased. And you can't forget GetUserData/SetUserData (if that even exists in the AS3 version).

(This was all complicated by the fact that there are both shadow classes and actual C++ implementations, original C++ library functions had to be wrapped and replaced to lessen source code modifications, void pointers don't work so well with SWIG, and all sorts of other fun things that are off-topic)

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