In one of my wp8 apps I am using BindingReflector to enable binding on converter parameters. One issue I ran into was is that any converter that is above (In XAML) the converter that uses binding on the parameter does not get GC'd at all. I noticed the page that was using this specific ordering get more and more memory when navigating to it then back and repeat.
After so many attempts on trying to figure what's going on I decided to try and change their order in XAML making the one using the reflector at the top and the problem was solved. I was wondering if anyone could have any explanation on this.
When I was having this mem leak problem, the profiler, under GC Roots, was showing that my converters were all referencing (not directly) the converter using the reflector with a Handle (WeakRef). No clue how could that happen but now once they're bellow it everything is fine and getting GC'd properly.
Note the converters were all in siblings controls, the structure was basically a listbox like this:
<ListBox ItemsSource={Binding...}>
<!-- ... item template like below -->
<controlX propX={Binding xxx, converter=....}/>
<controlY propY={Binding yyy, converter=....}/>
...
</ListBox>
EDIT: I have created and uploaded a simple test project which you can download the zip from here. Run the app, once MainPage loads click the button that takes you to Page1.xaml, hit the back button then click the button that takes you to Page1.xaml again and repeat this process.
I have included counters under the title of each page which show current memory usage, ofc you won't notice anything there but the next 3 counters are
- Current instance count of Page1 objects (yellow)
- Current instance count of the random converter objects (red)
- Current instance count of the converter using the binding reflector objects (green)
You will notice while yellow and green never go above 3, Red will keep going up as you go back and forth between MainPage.xaml and Page1.xaml.
Now, switch the position of the 2 button controls using the converters in Page1.xaml, just comment them out and uncomment the ones bellow them and you'll notice all 3 counters never going above 3.
EDIT 2: Apparently this isn't just about binding reflector. Having both buttons use the same converter will cause that specific converter instances not being GC'd. I don't know why this is happening..