Subject: | Does Promises::Promise contain a cycling reference? |
Hello,
This is not *exactly* a bug report, as I am still trying to unpick the logic in this module. (Just for fun, although it isn't particularly easy to follow.)
However it looks to me that Promises::Deferred->new constructs a Promises::Promise object, which refers to itself, and then stores that as an attribute in itself.
I can't find anything which breaks that cyclic reference. Am I missing something?
As this was translated from Javascript which typically has a fancier garbage collector than Perl's refcounting, my guess is that this actually works fine in Javascript, but nevertheless would leak in Perl. And if this is true there may be other more subtle memory leaks involving closures, although I've not spotted any so far.
Promises::Promise seems to be just a proxy for a Promises::Deferred, I'm guessing this is to isolate the users of the promise from the creator and prevent naughty things happening. P::P doesn't store any state of its own. Therefore I'm wondering if P::D actually needs to store a reference to a promise, or if the ->promise method could just construct one on demand.