Google Website Translator Gadget

Thursday, 30 September 2010

Understanding MSIL Memory Leaks

We are using a custom RuntimeDataBuilder class that dynamically constructs a .NET type in-memory using Reflection.Emit to create simple property getters/setters for the information that we receive from a generic WCF Data Service. The service exposes a "DataSet like" structure consisting out of 1..m DataTableDefinition classes each containing 1..m DataTableColumnDefinition classes. When the information is received client side, we generate the dynamic type with its property setters/getters to improve the performance and facilitate binding on our Silverlight client. All of this works fine.

I’m currently trying to figure out how the memory management for these custom dynamic types work.  I’m thinking that we might be causing a possible memory leak if we regenerate the type. Reason why I am contemplating this is that the user can change the query parameters which may then result in more/less information coming across the wire. It therefore invalidates the previous type that I created and I want to make sure that I’m are able to free up the memory used by this previous type definition as this can happen quite frequently.  From this article on MSDN we gather that if you are using Light Weight Code Generation (LCG) the code is allocated on the managed heap which will be reclaimed by the GC when there is nothing holding a reference to it. But LCG only seems to apply to dynamic methods. My concern is for the Type with all its property getters/setters that is now not required anymore. If this is allocated on the unmanaged heap our only hope for reclaiming the memory seems to be to make sure that the type is loaded into a temporary AppDomain that we can unload when it is not required anymore.  This opens up a whole new can of worms for inter AppDomain communication which I would rather avoid.

So my question is any of my readers can shed some more light on this topic.  Is my assumption correct or is there another way of reclaiming the memory?  I also posted the question to StackOverflow if you are interested in checking out the responses over there.  Thx :-)

Wednesday, 01 September 2010

Ultimate .NET Development Tools 2010 Edition

Here is my updated 2010 list of development tools that I prefer to use when doing .NET development.  I specifically do not include any third party control/report libraries.

Categories

  • IDE = Develop/generate/refactor code within the VS IDE or separate IDE 
  • SCM = Software Configuration Management (Source Control etc.)
  • TDD = Test Driven Development Tools
  • DBMS = Database Management Systems
  • CI = Continuous Integration
  • FR = Frameworks (Persistence, AOP, Inversion of Control, Logging etc.)
  • UT = Utility Tools
  • CA = Code Analysis (Static + Dynamic)
  • TC = Team Collaboration (Bug tracking, Project management etc.)
  • MD = Modelling
  • QA = Testing Tools
  • DP = Deployment (Installations etc.)

 

Tools

* = free/open source
  1. [IDE] Visual Studio 2010 Premium Edition
  2. [IDE] ReSharper for refactoring, unit test runner and so much more
  3. [IDE] CodeSmith for generating code.  Also consider T4 with Clarius’s Visual T4 Editor.  
  4. [IDE]* GhostDoc for inserting xml code comments
  5. [IDE] Altova Xml Suite for any xml related work.  XmlPad is the best, free alternative I know of.
  6. [DBMS] SqlServer 2008 for DBMS
  7. [SCM]* Subversion for source control
  8. [SCM]* TortoiseSVN as windows shell extension for Subversion
  9. [SCM] VisualSVN for integration of TortoiseSVN into VS.  AnkhSVN is the best, free alternative I know of.
  10. [SCM]* KDiff3 for merging
  11. [TDD]* NUnit as preferred xUnit testing framework
  12. [TDD]* moq as mock framework.
  13. [TDD] NCover for code coverage stats
  14. [CI]* TeamCity as build server
  15. [CI]* MSBuild Extension Pack for additional MSBuild tasks.
  16. [FR]* log4net as logging framework.  Also see Log4View for an excellent UI for the log files.
  17. [FR]* ANTLR and ANTLRWorks for creating custom DSL’s.
  18. [FR] PostSharp as Aspect Oriented Programming framework
  19. [FR]* Ninject as IoC container
  20. [FR] MindScape LightSpeed as my Object-Relational-Mapper.  NHibernate is the best free alternative I’m aware of. 
  21. [UT]* Reflector to drill down to the guts of any code library (also check-out the nice plug-ins)
  22. [UT] Silverlight Spy to dissect any Silverlight application.
  23. [UT] RegexBuddy for managing those difficult regular expressions.  Regulator is the best, free alternative I know of. 
  24. [UT]* LINQPad as a easy way to query SQL databases using LINQ and as a general scratchpad application to test C#/VB.NET code snippets.
  25. [UT]* Fiddler to debug all your HTTP traffic in IE.   Also see the neXpert plugin for monitoring performance problems.
  26. [UT]* Firebug to assist with testing web applications running in Firefox. Also see YSlow add-on for performance testing and Web Developer add-on for additional Firefox web development tools.
  27. [CA]* FxCop to enforce .NET coding guidelines
  28. [CA] NDepend to get all the static code metrics I'd ever want
  29. [CA] ANTS Profiler for performance and memory profiling
  30. [MD] Enterprise Architect to do UML Modelling and Model Driven Design if required. Alternatively use Visio with these simple templates
  31. [MD]* FreeMind as mind mapping tool
  32. [TC]* ScrewTurn Wiki for team collaboration
  33. [QA]* Eviware soapUI for functional and load testing of SOA web services
  34. [QA]* Telerik WebAii Testing Framework for automated regression testing of Web 2.0 apps
  35. [DP]* Windows Installer XML (WiX) for creating Windows Installers