Hi KYATRIC. The fix you suggest doesn't seem to fit with the explanation in that link. Could you help me to understand how this works. I have created a capx based on the OP's, reproduced here.
[attachment=1:3lv3lwuv][/attachment:3lv3lwuv]
Without the wait(0) at event 4, the log output is as follows, showing that only 9 sprites are destroyed (the 9 in the initial layout, and not the 10th created in the function).
(9) created a sprite
createObject()
created a sprite
destroyObject()
(9) destroyed a sprite
With the wait(0) the output is as follows:
(9) created a sprite
createObject()
created a sprite
destroyObject()
(10) destroyed a sprite
Which shows all 10 sprites being destroyed. However, we have not altered any events, just added a wait. This doesn't fit with the statement that newly created sprites are "... not picked ... until the end of the next top-level event".
In the above case the 'next top-level event' after event 4 (in which the object is created--via function call) would be event 5.. which we do not reach between the two function calls. So the wait(0) is actually a 'yield' which allows the next tick to occur, and so running subsequent top-level events.
Finally, if you agree with the above, then perhaps the wait(0) is actually a reasonable solution?