Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
405
Memory leak? Disposing issues, images, etc...
posted

Here's a ? I haven't found an answer to yet... I've read about images needing to be disposed if they are used in teh grid, but I'm not seeing how that'll work in my situation. Here's my situation:

There are two tabs (realistically, there could be 10 tabs).  I have one grid that lives in a panel. Panel contains the grid and a tool strip.  When the user switches between the tabs, the panel is added to the controls collection of the currently selected tabpage (which automatically removes it from the one it was in).  The tabpage.tag property contains a settings object I've defined which contains a datatable and a memory stream (the saved layout of the grid).  I save the datatable so I don't have to rebuild the datatable every time the tab is displayed. 

The problem is that once I've loaded the 2 tabs, thus creating both datatables and memory streams and attaching them to the tabpage.tag properties, I notice my memory usage is jumping every time I switch back and forth between the tabs, even though nothing is really being created on this action (aside from the first time the tab is accessed, of course).  Slowly the memory grows until (not yet) a possible OutOfMemory exception.

Any thoughts on why this is happening.  All that happens on subsequent selecting of a tab is:
  1) The grid panel is moved
  2) The grid datasource is set to the saved datatable
  3) The grid layout is set to the saved layout memory stream

I read that images could be the problem.  There are some images in this grid, depending on the data situations.  We have some 16x16 pngs that are inserted using the following code: 

    .Cells(cell.Column.Key).Appearance.Image = My.Resources.lock

I do know that if I put one of these images in every cell of my grid, it'll crash with an OutOfMemory exception... so my guess is the images may be what's making the memory usage grow.  I'm not doing anything to deliberately dispose of them when the datasource is changed.  If you think this may be the culprit, how would you go about disposing of them?  Spin through every row and cell in every band, look for an image and if it's there, dispose of it? It's brute force, but what else can I do?

Thanks for your help...

Rocky

Parents
No Data
Reply
  • 469350
    Offline posted

    Hi Rocky,

    What version of the grid are you using?

    Are you applying a different image to every cell? That would certainly use up a lot of memory, and there are more efficient ways to do that by re-using the same image and the same Appearance object in multiple places. Check out the WinGrid Performance Guide.

    But either way, that would not account for any memory leaks unless something in your code is created new Images or Bitmaps and not disposing them when they are no longer in use.It doesn't sound like that is the case.

    It's also possible that the rise in memory usage is not a problem at all, but just a result of the fact that the garbage collector has not been triggered. Try this and see if the memory usage comes back down:

    GC.Collect();

    GC.WaitForPendingFinalizers();

    GC.Collect();

     

     

Children
No Data