0

my program is a CRM, I used Rad Ribbon Bar, so Many Buttons with images, RadGridView (which some columns contain images) and so many other controls which contain images. It's a mdi parent/child program. In so many cases while loading a mdi child or working with some grid views the program will hang and give me this error:

OutOfMemoryException occurred in System.Drawing.dll

I can not find where and which image causes this error, nothing will show just the error title.

I tried GC.Collect() on certain parts but no success. So How can I find which image or control is causing this problem or how can I clear all images from the memory before loading a mdi child?

UPDATED:

as for codes, really for setting images there is no code! for example for setting an image for a button I used its properties in visual studio. I have set All other control images in this way using the properties panel in visual mode.

enter image description here

and These are some designer codes related to drawing:

    this.backStage.Size = new System.Drawing.Size(1151, 625);

    this.MainRibbonBar.Font = new System.Drawing.Font("B Nazanin", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(178)));

    this.btnCustomerList.Image = global::MihmanyCRM.Properties.Resources.CustomerList32;

    gridViewCommandColumn1.Image = global::MihmanyCRM.Properties.Resources.ViewShop32;
Inside Man
  • 4,194
  • 12
  • 59
  • 119
  • 1
    I think you should post your code, may be someone will spot the memory leak, using your description only will be very hard to provide an answer. – Isma Nov 01 '17 at 08:22
  • without enough code to recreate it - people here cant help you – BugFinder Nov 01 '17 at 08:27
  • I have updated my post – Inside Man Nov 01 '17 at 08:51
  • @SirRufo it is not duplicate at all. – Inside Man Nov 01 '17 at 08:53
  • @Nofuzy check out a web search for *OutOfMemoryException System.Drawing* - there are countless results dealing with the same problem – Sir Rufo Nov 01 '17 at 09:05
  • But the solutions are different, some people are setting images programmatically so they can find the exact location of error by some searching and testing. But I'm setting images visually and I do not know which one will cause this error and why? and How to find and manage the error location. – Inside Man Nov 01 '17 at 09:11
  • How can we find and manage the error location without seeing any of the code you can see? – Sir Rufo Nov 01 '17 at 09:16
  • The exact problem is this. There is no code! I'm setting images visually for each control by the properties panel of each. But the errors will come and I do not know how to manage them. So I'm looking for a way fixing it. – Inside Man Nov 01 '17 at 09:17
  • If there is no code, then you have no error. So there must be code. Setting control properties will also result in code (generated by the designer). – Sir Rufo Nov 01 '17 at 09:20
  • The question is updated. – Inside Man Nov 01 '17 at 09:24
  • Some general tips: (1) reduce image sizes, e.g. do not use 2048x2048 if 64x64 is all the user will ever see; (2) allow items to be unloaded (*and garbage collected*) when not in active use, do this by not keeping e.g. a global list of (big) images or a global list of elements that contain (big) images. (3) If you have some 'preload everything' mechanism: either remove/disable it, or make it behave more like a 'cache' of items. – Peter B Nov 01 '17 at 09:26

0 Answers0