Memory Leak and Increased Process Memory in UWP App Load the ListBox Items when Opening the Popups with Custom ListBox View

Anandhan Rajagopal 1 Reputation point
2024-02-12T12:59:24.1133333+00:00

Issue: The application's process memory exhibits a continuous increase, particularly noticeable when frequently opening and closing popups containing a custom ListBox view. This behavior suggests a potential memory leak within the UWP platform. Especially the issue occurs due to subscribing to the loaded and unloaded event in the prepare item container override method of the list box. we have unsubscribed the events properly but still, the memory leak occurs.

Details:

  1. Reproduction Steps:
    • Open the application.
    • Perform actions to trigger the opening and closing of popups containing the custom ListBox view using the click button.
    • Repeat the process multiple times.
  2. Expected Behavior:
    • The application's memory consumption should remain stable even with frequent popup interactions.
  3. Observed Behavior:
    • With each iteration of opening and closing popups, there's a noticeable increase in process memory usage.
    • The memory consumption keeps growing, indicating a potential memory leak.

Sample Link:

https://github.com/anandhan-rajagopal/UWPMemoryLeak

Issue Output Video:

https://www.syncfusion.com/downloads/support/directtrac/general/ze/UWPMEM~1-927750295

Universal Windows Platform (UWP)
{count} votes

1 answer

Sort by: Most helpful
  1. Junjie Zhu - MSFT 13,516 Reputation points Microsoft Vendor
    2024-02-13T08:02:43.8466667+00:00

    Hi @Anandhan Rajagopal ,

    Welcome to Microsoft Q&A!

    I can also reproduce the same behavior.

    At first, I also thought it was related to event registration, but it doesn’t seem to be the key point of this problem.enter image description here

    It is recommended to define max1 as a global variable, and the leak will disappear.

     List<object> max1 = new List<object>();
     public MainPage()
         {
             Employees = new List<Employee>();
             this.InitializeComponent();
    
         max1.Add(new Employee { Name = "Lucas", Email = "lucas@syncfusion.com" });
    
         max1.Add(new Employee { Name = "James", Email = "james@syncfusion.com" });
    
         max1.Add(new Employee { Name = "Jacob", Email = "jacob@syncfusion.com" });
     }
    
     private void popup_Opened(object sender, object e)
     {
    
         CustomBox.ItemsSource = max1;
    
     }
    

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments