Memory Leaks with SfPopupLayout Bindings

I am using SfPopups in my Xamarin Forms application and I have ran across a memory leak issue when binding to SfPopups. Every time i open a SfPopup with bound data in the PopupView, changing the bound data will result in the get property code being ran once for every time the SfPopup has been opened. The first time the popup is opened the get property code runs once every time the property is changed then after the SfPopup is closed and re-opened, the get property code is ran however many times the SfPopup has been opened whenever the property changes.


I have tested this on both iOS and Android and the result is the same. I have worked around this issue by using BindingMode.OneTime and then changing the property via control changed events however I am using a control without an optimal property changed event to bind to. 


I hope to see this fixed soon!


1 Reply 1 reply marked as answer

JR Jayashree Ravishankar Syncfusion Team July 5, 2024 01:20 PM UTC

Hi Bryson Scales,


We have checked the reported issue. We would like to let you know that views or data used inside the content template of a Popup view should be disposed of manually to avoid memory leak issues.


Please refer the following code snippet:

popup.Closing += PopupLayout_Closing;

 

private void PopupLayout_Closing(object sender, Syncfusion.XForms.Core.CancelEventArgs e)

 {

     var nativeObject = (object)(sender as SfPopupLayout).GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name.Equals("NativeObject")).GetValue(sender);

     var formsPopupviewContentTemplate = nativeObject.GetType().GetRuntimeFields().FirstOrDefault(x => x.Name.Equals("formsPopupViewContentTemplate")).GetValue(nativeObject);

     (formsPopupviewContentTemplate as Grid).Children.Clear();

     (formsPopupviewContentTemplate as Grid).BindingContext = null;

     formsPopupviewContentTemplate = null;

 

 } 


We have attached the sample for your reference. If you are still facing any issues, please share the content template of the popup view or the sample. This will help us reproduce the issue on our end and find a solution as soon as possible.


Regards,

Jayashree


Attachment: PopupLayout_9e42bd93.zip

Marked as answer
Loader.
Up arrow icon