Closed PMunch closed 3 years ago
Wouldn't it be better to create it with new
and then immediately call GC_ref
(and cast to ptr
)? Then it could just use seq
.
Since you return the MainLoop
you don't even have to GC_ref
it as the user will keep it around to call tick
or runForever
anyways. If you simply make MainLoop
a ref object
you pretty much solve the whole thing. But this solution is guaranteed to work even if the user doesn't keep the reference around, although it does require them to manually free it.
Since MainLoop is created with
create
the sequence stored within it isn't visible to the GC. So when it runs it doesn't find the reference to it and can therefore end up freeing it. This commit fixes #17 which was caused by such a scenario (probably because the Firefox notification included an icon which contains enough data to have triggered the GC). This also means that MainLoop can now be free'd manually if the user wishes to usecreate
andtick
withoutrunForever
.