locked
Clearing gridview's memory

    Question

  • Right now, I'm loading a lot of photos in a gridview and it is eating a lot of my apps memory. When I leave the page, it still looks like the memory is taken. I have turned off caching on that page that contains the gridview, but that didn't help.

    I'm using the powertools to monitor the memory. I try taking snapshots before/after, but then I stop the session, I get a catastrophic failure, so I never see the actual report.

    Thanks.


    mark

    Friday, October 24, 2014 8:04 PM

Answers

  • try to call GC.Collect() before leaving the page

    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

    That won't help cause gridview is native and GC only affects managed things.

    @OP

    You need to dereference the images. CLear the grid view's item source, then set the grid view to null.

    If you can, set each individual image source to null before clearing the item source.

    • Marked as answer by Mark_E_R Monday, October 27, 2014 2:50 PM
    • Unmarked as answer by Mark_E_R Monday, October 27, 2014 2:50 PM
    • Marked as answer by Mark_E_R Monday, October 27, 2014 2:50 PM
    Sunday, October 26, 2014 12:54 PM

All replies

  • try to call GC.Collect() before leaving the page

    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

    Sunday, October 26, 2014 9:25 AM
  • try to call GC.Collect() before leaving the page

    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

    That won't help cause gridview is native and GC only affects managed things.

    @OP

    You need to dereference the images. CLear the grid view's item source, then set the grid view to null.

    If you can, set each individual image source to null before clearing the item source.

    • Marked as answer by Mark_E_R Monday, October 27, 2014 2:50 PM
    • Unmarked as answer by Mark_E_R Monday, October 27, 2014 2:50 PM
    • Marked as answer by Mark_E_R Monday, October 27, 2014 2:50 PM
    Sunday, October 26, 2014 12:54 PM
  • Hi mcosmin:

    thanks your reply, I'd like to know is there any document about "GridView is not managed class".

    please tell me where can I find these papers, thanks. :)


    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

    Monday, October 27, 2014 12:43 AM
  • For this issue. GC didn't really help by itself. The thing that worked best was to set the GridView.ItemsSources = null.

    Things I have in place to help are:

    * GridView.ItemsSources = null

    * GC.Collect();

    * Page caching off.


    mark

    Monday, October 27, 2014 2:50 PM
  • thanks your reply, I'd like to know is there any document about "GridView is not managed class".

    The Windows Runtime is almost completely written in native code which is then projected into the various languages such as C# and VB (using .Net) and C++/Cx (staying native).

    There were a number of talks at Build 2011 which go into details on this.

    This isn't why GC.Collect won't help though. .Net apps will use the GridView class as though it were managed. The interop layer will hold a reference to the GridView so it won't go away until that reference is garbage collected.

    The problem is that the app still has a reference to the items and so they aren't eligible for garbage collection. Setting the ItemsSources to null removes that reference. There likely is a higher level reference that could be cleared as well, but we don't have enough information to know where exactly that is.

    --Rob

    Monday, October 27, 2014 8:24 PM
    Owner
  • Thanks Rob, :>

    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

    Monday, October 27, 2014 9:01 PM
  • I would say .net GC won't clear the entire memory. The reference chain is similar to this

    Interop Layer > gridview > grid view items's source collection > image > source

    If you interrupt the chain at any point between the gridview and the source, the items will get collected by winRT's collector. the reference will still hold the gridview, but its implementation's memory is negligible.

    Monday, October 27, 2014 9:05 PM