I was recently struggling with a memory leak somewhere in my code. My code which was running in the _LAYOUTS directory was handling content types across sites/lists in a SharePoint configuration.
On my local machine with a small number of lists/sites everything appeared to be fine, but when running on a test server I could see the memory in use on the server to jump up by several MB every couple of seconds. After a few minutes the memory on the server could be up to a over a GB. Eventually an OutOfMemory exception would be thrown.
I pulled all my code apart and ran some profiling tools to find the problem and it turned out to be an SPWeb which was being created and not being closed (unbeknown to me). So it was an easy solution once found.
I found this MSDN link very useful while looking into this and thought it would be worth highlighting for any developers working with SharePoint: