Search code examples
androidgarbage-collectionxamarin.androidtinyioc

Using TinyIoC in Xamarin.Android


I got a bit tired of tall the hard referencing that I found inside a Xamarin.Android app I inherited - Actions referencing actions, funcky stuff happening in callbacks etc. So I decided I would register the Actions in TinyIoC and resolve them when needed.

This kinda worked for a while until I started noticing strange stuff happening. If the app was left alone for a long time the app would crash - looking at the logs it's because the I-oC can't resolve one of the actions - where by it could before the app was left sitting for a long time.

This has GC written all over it - if you ask me. The GC is obviously somehow not seeing the items in the IoC as a reference and disposing of them.

Is this something anyone else has ran into? If so, how have you overcome this?


Solution

  • My advice would be to not use TinyIoC - or any IoC for that matter - to manage actions etc in Android. Android seems to want to manage state of objects in a way that gets broken when using IoC.

    This will lead to a host of problems which are hard - near on impossible to debug.