The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
UWP] Memory leaks in UWP C# ObservableCollection RRS feed

  • Question

  • Hello. I have an ObservableCollection in my project which uses usercontrols to show data. Before this list will be filled again I clear all data use myList.Clear() but my memory consumption looks bigger. Memory snapshot shows me +900 objects in memory heap and after clearing it shows -100.

    I've attached the sample.

    Sample project



    Sunday, March 31, 2019 3:31 PM

All replies

  • Hello,

    Memory means your memory will always grow up and finally fills all the memroy. But when I run your app the memory keeps at 40MB. I don't see any memory leak here. I can only see cache raised when you call clear, but that's not memory leak. 

    Best regards,

    Barry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, April 1, 2019 10:03 AM
  • I set 50 in "for" cycle.

    When I click "Fill" button I see

    After cleaning only "App3.MyUserControl1" looks like "-50"

    What's the point to store ConditionalWeakTable in memory after cleaning?

    In my real project memory(in debug) growth like 150mb, 160mb, 170mb, 180mb and so on after every update(cleaning and filling ObservableCollection).

    It doesn't look normal.

    I should say that after calling GC.Collect() all 450 object are cleaned.
    Monday, April 1, 2019 3:36 PM
  • Hello,

    To understand ConditionalWeakTable please check the following:

    1. ConditionalWeakTable<TKey,TValue> Class

    2. Weak References

    So in general, here are some related things:

    "The ConditionalWeakTable<TKey,TValue> class enables language compilers to attach arbitrary properties to managed objects at run time. A ConditionalWeakTable<TKey,TValue> object is a dictionary that binds a managed object, which is represented by a key, to its attached property, which is represented by a value. The object's keys are the individual instances of the TKey class to which the property is attached, and its values are the property values that are assigned to the corresponding objects."

    "A weak reference permits the garbage collector to collect the object while still allowing the application to access the object."

    And as they are weak reference, when you call GC.Collection() they will be cleaned. 

    So my question is that, is it really nessary for you to put so many usercontrols there in your list? And why is it required? 

    Best regards,

    Barry 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, April 2, 2019 7:44 AM