MVVMCross - SqlBits Memory Leak

2019-08-12 00:36发布

问题:

We are developing an Monotouch application with MVVMCross similar to SqliBits sample (the UINavigationCOntroller has a tab controller and inside the tab controller there is anothe navigation controller). It seems that the memory gets allocated but never released.

To reproduce this error launch the SqliBits sample with the profiler select Sessions tab and then select a day go back, select a day go back,... and then look at the memory allocation and you will see that trhe memory gets allocated but never released.

I am allowed to attach an image yet but it is fairly easy to reproduce the error.

Regards, Dan

回答1:

As an issue, this has been discussed on https://github.com/slodge/MvvmCross/issues/19

iOS only frees up Views (via View Controller ViewDidUnload method) when there is a memory shortage - within the Simulator this can be artificially created from the Hardware menu.

Beyond this, there was also a small memory leak which looks like it was caused by a reference to the ViewModel in the Action fields within the RelayCommand. It's not entirely clear to me what caused this, but adding Dispose methods to the RelayCommand which nulls this Action seems to have removed the problem (see https://github.com/slodge/MvvmCross/commit/8fc1af3fc9960445b5358daf8111f6bc9683b907)