# Problem with Circular References

## Recommended Posts

Marcus L    235

Hi again

So, I've stumbled across a strange issue with circular references. It seems AngelScript doesn't like it when I feed a member variable a reference to its owner (not too surprising, all things considered).

Here is an example of what I mean: (I'm using the "any object"-addon in this example)

class A
{
any test;
A()
{
test.store(@this);
}
}

void main()
{
A a();
}


After running this code, I get the following error messages as I exit my application:

ERR:  (0, 0) : ERR : Object {4}. GC cannot destroy an object of type 'A' as it doesn't know how many references to there are.
ERR:  (0, 0) : ERR : Object {5}. GC cannot destroy an object of type 'any' as it can't see all references. Current ref count is 1.
ERR:  (0, 0) : ERR : Object {76}. GC cannot destroy an object of type '_builtin_objecttype_' as it can't see all references. Current ref count is 2.
INFO:  (0, 0) : INFO : The builtin type in previous message is named 'A'


While this doesn't actually cause any memory leaks as far as I can tell, I still suspect this might lead to problems. I have tried to call scriptEngine->GarbageCollect(asGC_FULL_CYCLE) before scirptEngine->Release(), same result. So now I'm wondering what might be causing this. Is this expected behavior perhaps?

(I'm using AngelScript 2.29.0 btw)

##### Share on other sites
Marcus L    235

Never mind. Seems it was a mistake on my part (had modified the EnumReferences callback ).
Mods may delete this thread if they wish (the manual answered all my remaining questions).

Edited by Bitsauce

##### Share on other sites
WitchLord    4677

Ah, thanks for confirming that it was not a bug.

##### Share on other sites
Marcus L    235

No problem . Sorry if I caused you any headaches!

Edited by Bitsauce

## Create an account

Register a new account