07/04/16 Manage memory like a pro When was the last time you thought about memory management, assuming you're an application developer? When was the last time you thought about memory management, assuming you're an application developer? Java and C# and other computer languages have been hiding this aspect of software from developers. However, they have performative issues. Developers don't profile their applications, and sometimes, just sometimes, they struggle to find out why their application is slow. Time spent on dealing with memory problems is time when you do not write your app. The hard part is knowing when is the right time to start being concerned about problems. As the lecturer from the previous Geekstone meetup, Ivan Nemes, said, some things are “rarely mentioned among developer’s circles but they are quite important for development of qualitative applications”. In his very interesting and detailed lecture, we could hear information about handling the memory and its organization in .Net applications, such as how to properly implement Disposable pattern, what are destructors used for… Ivan engaged with the topic of memory profiling and the best practice for memory management. As he said, memory management is underestimated by developers and people often do not pay attention to it because they think that in .Net applications engine itself takes care of everything. -It’s true that .Net liberates the objects for you (except unmanaged resource), but it is quite easy to misuse .Net engine and get into memory issues. These issues can cause the application to slow down or (even) to fail. Often memory issues are quite complex and hard to be analyzed and they can give quite a headache. Hence, it is very important to know a good practice when it comes to the memory management- explained Ivan. Challenge lies in small details For developers, it can be challenging to think on the lower level when it comes to writing the C# code. As Ivan mentioned, you need to have discipline and implement a good practice to find solution. For example, you need to pay attention on the way of initializing the arrays, handling strings etc. Wrong handling of memory can cause various problems; of whom some are obvious while others demand time to be solved. In light of what Ivan said, you have to refactor/change whole modules and frequently the whole architecture of an application because it is not performative and memory consumption is big, which happens more often than we want to admit. One of the demanding challenges this developer has come across, was the demand for an application to work for a long time and transfer big amount of data. The challenge was also to keep it stable and functional, regarding the performance and memory consumption. In that moment he had to think about small details and really to know how .Net works under the hood. -All these “small things” can have radical influence on the final functionality of the application. I solved the problem because I realized how the memory looks like in .Net. After profiling memory, I got the information that were needed to refer on weak spots in my application. It was necessary to get to know the details of .Net memory management so that I could understand the information I have got from the tool used for profiling- Ivan recalled while he was presenting how some tools work. Developers as profilers After hearing his lecture, you might get impression that developer should have some profiler skills. Certainly, that is not the wrong conclusion. Ivan said that this skill is very useful if you want to build the application retaining high performances or improve existing one. He also shared a few memory management tips: - Get to know the way of memory work in .Net. You do not need to know every detail of garbage collector work. - Check what is the best practice so you could avoid memory issues and include some of the rules in your daily coding routine. - You should expect memory issues, do not treat them as isolated and rare cases. Ask yourself, what could happen with the application if you forward a bunch of data to it, what could happen if it would work for a long time. Our young developer from Vega IT Sourcing concluded: “And in the end, bear in mind that knowledge of memory management will make you feel more confident while you are developing the application. And that has certain value…” By Andrea Jerinic