Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Summary of current best practices for event handlers and disposing

$
0
0

Recently I've spent some time tracking down why some objects were not getting garbage collected. I've read through various discussions on reasons why and what to do but it feels like there is variance in the recommendations. Also, the samples I've seen on github or the field service app also seem to be inconsistent. And one more factor, I'm a little unclear about how it might have changed post ios6 which seems to have affected the steps required to clean up events and/or dispose items.

Some resources on the topic include...

Discussion threads

Evolve video session on advanced mem management

Docs

Samples

My working conclusion at this point, is that for a normal ViewController:

  • subscribe to events in ViewWillAppear
  • Unsubscribe to events in ViewDidDisappear
  • Dont call dispose unless you have an expensive (big/rare) resource
  • due to the need to unsubscribe, lambdas must either be in a local|instance field, or use a formal method
  • that's it

But it feels like there's more to the story. @Rolf or anyone want to chime in on current best practices?

Dennis


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>