|Think about Loose Coupling|
So I'm not supposed to mortalize the scalars that I push onto the array? Why is that? It makes my problem disappear, which I like, but I don't understand it, which I don't like. Any further thoughts are appreciated.
When an object is freed due to its refcount going to 0 all the items that object references have their refcount decremented in turn. So if you stuff an AV with mortalized SV'es the SVes could be freed before the AV itself tries to do the refcount decrement on the scalars it contains. Which then raises a warning as this kind of thing (at least from the perl side point of view) shouldn't happen.
So if you think about what happens in:
Its a recursive process:
In reply to Re: perlembed: mortalize an AV, get "Attempt to free unreferenced scalar" - don't mortalize, leaks memory