Tuesday, 17 February 2015

How to investigate memory leak in .NET applications

In .NET eco-system we are used that memory is managed for us. It is allocated and freed up when not in use anymore. We do not have to worry about it. But even in .NET we need to think about such things like memory and external resources.

I received a complain from one of our customers, that the memory usage of IIS goes to extreme. In addition the following exception was thrown:

Insufficient winsock resources available to complete socket connection initiation. An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full 127.0.0.1:8028

We started with attaching dotMemory profiler to the IIS process. Here is the screenshot of process's memory:
We can see from the above picture, that the amount of memory used grows over time. It looks like memory is not released. 

In order to understand what kind of objects are not being released, we took two snapshots during the profiling: one in the beginning of our profiling session and another one at its end. Then we compared those snapshots. From the comparison we selected Grouped the objects b namespace and then right-click and "Open Survived Objects". Survived objects are those that weren't released between the snapshots.



In the list of survived objects, we grouped them by Dominators and got the following picture:


From the above picture we understand that instances of TranparentProxy are not closed. It looks very connected to the "insufficient winsock resources" error we receive.

So now to the easy part: fix the code :-)
We wrapped any service call with a try/finally block. In the finally block we close the open proxy, which also closes the socket.

After applying the fix we executed dotMemory profiler to see how memory behaves. Here what we got:

The picture looks completely different: instead of steady increase, we see those drops in memory usage. The drops are of course result of Garbage Collection. 

Happy profiling!

UPD: As @volebamor mentioned in his tweet: "it's more obvious to open new objects instead of survived". Thanks for your comment!



Sunday, 8 February 2015

Slides for my talk "Continuous Integration in Action"

Slides for my recent talk at Clean Code Alliance meetup group titles "Continuous Integration in Action". During my talk I focused on the basic principles of  continuous integration and shared from own experience some tips for its successful and effective implementation.

Here are the slides:


Continuous Integration in Action from Boris Modylevsky

I would like to thank Itzik Saban for reviewing the slides and helping me rehearsing the session. It would not happen without you.



Tuesday, 7 October 2014

How to improve your ReSharper proficiency

Many developers that start working with ReSharper realize that the learning curve is steep. There are many hidden features, many shortcuts that need to be memorized, there are many tricks that one can do in order to improve his/her productivity. So here is what I did to help my colleagues to help them learn ReSharper.

I created a REST API that returns random ReSharper tips or trick. Its source code is available on github:

https://github.com/borismod/ReSharperTnT

I used AppHarbor for continuous integration and cloud hosting. So at the end, the REST API is available at the following URL:

http://resharpertnt.apphb.com/api/tipsandtricks/

It returns random ReSharper tip or trick in JSON format:









Then I incorporated the above REST API in our command-line build process:







So every time we build, we see random ReSharper tip or trick.

Enjoy coding!

How to write to console from Windows Application



When creating a Windows Applicaiton, either WinForms or WPF it does not have console. Converting the application to Console Application seems to solve the problem. If we execute our application from a console, it will be able to print to console and everything seems to be fine. But when we run it not from a console  a new console window will appear in addition to the existing Form or WPF Window. So what we can do?



AttachToConsole will actually attach to the parent console from which the Windows Application was executed. Unfortunately, it does not move the cursor to the next line. Thus the next line is required Console.Writeline.



Sunday, 24 August 2014

Must have tools for Windows

Each one of us uses some tools that makes his/her life easier. In this post I would like to share a list of very essential tools save a lot of time and let us focus on what is really important to us. The tools have a common denominator: they help to get things or get things done. Please note the difference in terminology. Sometimes in the past there was File Manager and we had the feeling that we "manage" files. When the amount of files increased it was replaced by Windows Explorer. So we had the feeling or exploring things. Then a Search button was added that should have help us to find thing. Unfortunately it was pretty slow, so we still go lost among the files. Nowadays in the 2014 we want to "get" instead of search, manage or explore. So the tools you'll see here focus on getting programs from the internet, getting files on your computer, getting programs on your computer, getting you passwords etc.

So here they are:

1. chocolatey.org - is the ultimate installer for every program for Windows. It has an enormous catalog of pro grams for download with a one line command line. So it is the new way to "get" programs to your computer.

2. Everything -  is the fastest and most effective way to "get" files on local computer. Unlike built-in Windows Search, it is extremely fast, it does not interfere with other programs, such as anti-virus software or files written by compilers or test runners. And it can be invoked with a shortcut. I prefer WinKey-N, for the similarity for the ReSharper and IntelliJ Ctrl-N, but it is completely your choice.

3. Launchy - is the fastest and most elegant way to execute eny program on your computer. It can be invoked with a shortcut (I use Alt-Space) and with typing a few characters it finds any program you need. Launchy has also some useful pluigns like: Killy, Tasky

4. Console2 - command-line console has been for many years the way we like to execute things. But the built-in console is poor and lacks of many features. Console2 is the new and must-have console application. Among its features: multiple tabs, copy-paste with keyboard shortcuts, resize. After installing Console2, follow step described by Scot Hanselman here.

5. Dropbox - needless to say how it is important to keep all your files synced between different machines. Dropbox is one of the popular and  convenient ways to do it.

6. Lightshot- this small and non-intrusive application helps to take screenshot. It allows cropping your screen while taking the snapshot, then editing it on the spot and then copying to clipboard or saving to file. By copying to clipboard and then pasting to the desired application (even to Gmail) you can save a lot of time.

7. Keepass - we need to keep track of our passwords and there are plenty of them. Every website, every application require its own authentication. Keepass allows storing all your passwords in a single encrypted file. The file can be protected by master password, external file, Windows User account or any combination of those methods. I suggest saving the Keepass file in Dropbox folder for easy access from different machines.

All the tools listed above are free.