Distributed Objects, delegates, and retain cycles

  • I'm using Distributed Objects to perform a long operation in a
    separate process. The vended object communicates the operation's
    progress by calling a method in its delegate. The problem is that if
    the object doesn't retain the delegate then the proxy to it goes
    away, so its pointer becomes stale. On the other hand, if it does
    retain the delegate, the retain gets propagated back to the client;
    but the delegate happens to be the object that's retaining the vended
    object, so I get a retain cycle.

    Is there a good solution to this problem?

    Derrick
  • Hello Derrick,

    On Mon Oct 02 2006 at 01:42, Derrick Bass <derrick...> wrote:

    > I'm using Distributed Objects to perform a long operation in a
    > separate process. The vended object communicates the operation's
    > progress by calling a method in its delegate. The problem is that if
    > the object doesn't retain the delegate then the proxy to it goes
    > away, so its pointer becomes stale. On the other hand, if it does
    > retain the delegate, the retain gets propagated back to the client;
    > but the delegate happens to be the object that's retaining the
    > vended object, so I get a retain cycle.
    >
    > Is there a good solution to this problem?

    I'm not sure about other solutions, but when I faced the same problem,
    I ended up with retaining the delegate (proxy) and creating the retain
    cycle. I decided to follow one simple rule of thumb not to be affected
    by the cycle: make the object that *sets* the delegate responsible for
    resetting it to nil when appropriate (and therefore breaking the
    retain cycle). It worked for me, and moreover, helped to keep the
    model "clean".

    Regards,
    Grigory
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today