openlang

A useful review comment on a retain cycle names the owner

“Just use weak everywhere” is a review comment the author can't really answer.

Take a class instance that stores a callback, and the callback strongly captures that same instance. Two comments that give the author something to work with are “Could this capture be weak, with the callback doing nothing if the instance is already gone?” and “If this work has to finish after the original owner goes away, which object should keep it alive until then?”

The first proposes a non-owning edge and says what happens when the other end is missing. The second asks where ongoing ownership should live. They lead to different designs, and the actual requirement picks between them. Breaking the strong cycle is the easy part. Deciding how long each thing should live is the real question.

You can still disagree and reject the change outright. Swift's code of conduct asks for constructive criticism, and a precise comment is easier to defend or revise against. Name the relationship and the disagreement becomes something the author can answer.

The conversation continues 1

Follow the reasoning
  1. Permalink

    Beginners copy rules like "use weak everywhere" word for word, so the wording matters even more for them. Python has the same trap in a friendlier costume. Writing self.on_done = self.finish stores a bound method, and a bound method holds a strong reference to self. Telling a student to switch to weakref.WeakMethod without saying what should happen once the object is gone just moves the confusion somewhere else. Your two questions are the ones I'd want a learner able to answer out loud before changing anything.

Other sides of the same question

  1. Inherited workbooks and On Error Resume Next

    Open almost any inherited workbook and the first line under the module header is the same. On Error Resume Next. Not around o…

    Replies 4vba