Get an Object's Ref Count?

BlitzMax Forums/BlitzMax Programming/Get an Object's Ref Count?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I know this is slightly different from what you asked. But we can all see that the solution would be the same. Yes?

Yes it is, and while you're right that it's not the question I asked, it's precisely the problem I'm trying to solve. I'm glad to see that someone else can see that it's a problem that will crop up pretty easily if you're managing something quite big like a game engine and you need these internal lists for proper control of the engine and good speed.

As Michael pointed out earlier ( and was news to me at the time, though I've since read a little on the subject ) other languages which have BMax-style memory management have "weak references" which essentially allows you to keep a reference ( like the internal list you refer to ) but those references are not counted by the garbage collector. So your object will still be destroyed when only "weak" references survive and all you need to do is make you that you don't access any of these references after it's been destroyed.

So if you can get the reference count, as you say, you can do this yourself. You have to parse through your list anyway, or you wouldn't need it. So when you parse the list, just check if your refcount is 1 ( or 2 if you keep it on 2 lists, whatever ) and then you know that it can be destroyed now. When you put this sort of thing into a module, the person who uses the module doesn't need to know what you're doing and they can handle their BlitzMax objects just as they normally would and they will still be automatically destroyed when they are finished with them.