>The test code from my previous post is run as described. I understand that
the delegate { } call will cause by view controller to be referenced; this
is desired. Even though my VC is referenced I expect that the view, which
my WeakReference is targeting, should be removed at some point.

That's the problem. You confused C# runtime and iOS SDK. WeakReference and
hard references are C# objects. iOS knows nothing if it is a hard reference
or a weak reference - it lives its own life. WeakReference tells GC it can
collect this object if there are no other hard references to it. Since
there is one (delegate), this will never happen.

Also, if GC decides to collect the VC, it will remove it completely. Both
view and controller which is not what you want.

Instead, you should call the DidReceiveMemoryWarning method when you want
to release the view but not the controller.


-
Ivan

2011/11/2 shawnlehner <[email protected]>

> Thanks Robert.
>
> What I am doing right now is testing how to properly release the view of
> one UIViewController that is being referenced by another UIViewController.
> In the case here I am doing the following:
>
> 1) UIViewController A is my master view controller; B is my child
> controller.
> 2) A creates an instance of B and stores the reference.
> 3) A adds B's view as a subview.
>
> Everything is right with the world. I see B's view correctly shown in A's
> view.
>
> 4) A removes B's view. B's view is now not referenced anywhere in my code.
> 5) I invoke DidReceiveMemoryWarning (via Simulate or manual call).
>
> The test code from my previous post is run as described. I understand that
> the delegate { } call will cause by view controller to be referenced; this
> is desired. Even though my VC is referenced I expect that the view, which
> my WeakReference is targeting, should be removed at some point. I want to
> keep my VC and its specific settings in memory for later use but I want the
> View to be unloaded. The next time I use this VC I would expect that
> ViewDidLoad() would be called when I attempt to add it's view.
>
> This is not the case. My WeakReference reports that the view stays alive
> even though there are no active references and the memory warning was
> registered.
>
> Does this make sense?
>
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to