0

stackoverflow. I've written a application in C# (a raytracer). Problem is not with raytracer but with ray usage. Application keep consuming more ram over time.

Ram usage while not raytracing : start with 10mb goes up and up

Ram usege while raytracing : start 80mb then 120mb and up, if resolution is big this number is up to 500mb.

I looked to VS Diagnostics tool and see application garbage collection is like 10 gc in 1 minute. This number is even bigger while application is raytracing. Raytracer returns a gigantic pixel array. I set pixel array to null after raytracing but application ram stucks in a range of 500-600 mb ram.

Are there any options to collect more garbage or free ram?

EDIT This is a WinForms application, not WPF or something.

Yahya Gedik
  • 97
  • 1
  • 12
  • 1
    Why is 500MB _too much_ ? And it will return mem to the system when that's useful. You are looking at the wrong numbers. – H H Aug 21 '16 at 11:36
  • 500 mb is not much while raytracing, even after raytracing 500mb still exists in program memory. – Yahya Gedik Aug 21 '16 at 12:39
  • @Yahya Gedik, use memory profiler, for example, [dotMemory](https://www.jetbrains.com/dotmemory/), to get more details. It might be possible that you have memory leak. – Artavazd Balayan Aug 21 '16 at 12:47

2 Answers2

2

I cant be sure since there is no code, but it sounds like a memory leak. Verify that there are no static object referencing the problematic object. To verify, run GC.Collect() after you set the object to null since if its in generation 2 for example it might take a while for the garbage collector to check it and reclaim it's memory. if after GC.Collect you see that the memory is not reclaimed, you most likely have a memory leak somewhere. If you cant find the location of the rouge reference, you can use tools like this https://blogs.msdn.microsoft.com/visualstudioalm/2015/04/29/diagnosing-event-handler-leaks-with-the-memory-usage-tool-in-visual-studio-2015/
Good luck

Yuval Perelman
  • 4,499
  • 1
  • 22
  • 32
  • Thank you, with VS diagnostics tool I figured out where the problem is. I forget to delete raytracer image array after tracing but before returning. – Yahya Gedik Aug 23 '16 at 11:57
0

Can i recommend you attempt to identify if any memory leaks are contributing to the progressive increase of memory usage of your application. There are plenty of free and paid tools that are available to achieve this task, along with endless advice on how to go about using them. The vs diagnostics tool has the ability to snapshot the memory usage of your application identifying where it is in use and what class types are present. Further information and example of use for the VS diagnostics tools can be found here : https://channel9.msdn.com/Shows/Visual-Studio-Toolbox/Visual-Studio-2015-Diagnostic-Tools

Further Help : What strategies and tools are useful for finding memory leaks in .NET?

Similar searches for ".net identify memory leaks" on here and other platforms will also help.

Commonly memory leaks are caused by the incorrect disposal and the retention of circular references, so identify any locations across your code where circular references are present.

Community
  • 1
  • 1
S_BatMan
  • 505
  • 6
  • 13