- AspDotNetStorefront (28)
- Business (20)
- Canadian eCommerce (42)
- Canadian eCommerce Benchmarks (3)
- Careers (3)
- Design (1)
- eCommerce (64)
- Ecommerce Toronto Meetup (10)
- Magento Commerce (21)
- Magento Extensions Updates (4)
- Magento Video Tutorials (1)
- Monthly eCommerce Statistcs (4)
- Ramblings (8)
- Salesforce.com (2)
- Search Engine Optimization (1)
- Social Media (9)
- SocialGift.com (1)
- Sports South (0)
- This Week in eCommerce (13)
- User Experience (1)
- Ecommerce Toronto Meetup #11 – Fraud
- eCommerce Trends for 2012
- This week in eCommerce – Jan 2012
- Is Your Magento EE 1.10.1.1 Admin Product Saving Extremely Slow?
- Ecommerce Toronto Meetup # 10 – Online and Offline Returns
- Demac Media Partners with Shop.ca
- Calculating Lifetime Customer Value in Magento
- Canadian eCommerce Statistics Series – December 2011
- My office so far! @demacmedia http://t.co/AajVcHMH
- Some desks already setup in main area. http://t.co/ag8m2TYt
- The guys taking a break from setup. @demacmedia http://t.co/xHI56DDH
- Main room before move in. http://t.co/70rHSRGR
- Chaos today at @demacmedia. #moving to bigger / badder offices.
- @mbertulli http://t.co/gp8gSPE1
- RT @DealuxeCEO: Cat's out of the bag! @ssheffman is taking a new direction as Fashion Director @ShopDealuxe. Taking online retail to new ...
- my company creates..and sometimes run, high-performance #magento e-commerce websites..this is one of them: www.dealuxe.ca
- moving on up, literally ....to a new office space above us....what have we created? @mbertulli @demacmedia @JenaBela
- up "late" hacking..man I'm getting old, this used to be my prime time.
- Let's do this ! (@ Bloke & 4th) http://t.co/MwZvZ32b
- I'm at Wynn Fitness (98 The Esplanade, Church, Toronto) http://t.co/wH5AAdCP
- RT @dcolomvakos: moving on up, literally ....to a new office space above us....what have we created? @mbertulli @demacmedia @JenaBela
- @demacmedia http://t.co/y3MaL0M1
- 2012 eCommerce trends http://t.co/HF1Y9NMJ
- A few articles from this week in eCommerce. First of the year, so articles sum up the month so far http://t.co/GUxGJrmT
- @demacmedia blog: Is Your Magento EE 1.10.1.1 Admin Product Saving Extremely Slow? - http://t.co/oDucFqyk
LINQ to XML XElement Memory Problems
Let me just start by saying that this post is one of those weird ones where it probably serves more function as a “lookup” for a very fringe issue in the off chance we run into it again.
We’ve recently been doing some work with the book publishing industry ONIX file format, which for those who don’t know, is an XML schema for moving book product data between publishers, distributors and retailers. When we were asked to bring the ONIX format into the AspDotNetStorefront eCommerce platform, we decided to build an integration service that used LINQ to XML to work with ONIX. We’ve used LINQ to XML in the past and found that it’s speed to develop with was important for this job (the code is just really nice to write).
All was going well until we started testing the service with ONIX files that contained north of 20,000 records, roughly 75MB of XML in size per file. The service started to chew up several GB of RAM while running, clearly the result of a memory link somewhere in the entire process. After smashing our heads against the wall I decided to grab a free trial of the Redgate ANTS Performance Profiler to see if they might shed some light as to why we were leaking memory from a rather simply set of functions.
The ANTS Profiler showed us that our major culprit was the XElement object that is part of LINQ to XML. So we began googling around to see if anybody else was having similar problems. There were hints here and there that some were experiencing this issue but nobody seemed to be solving the issue except for changing their method of XML manipulation to using traditional stream readers/writers.
Then, one of our senior developers (Dimitri) took a look at the code and saw that we weren’t calling RemoveAll() on our container XElement that held all the manipulated xml. Before you comment, know that this XElement was contained in a separate class that was instantiated + destroyed every 50 records or so in an attempt to work in smaller more manageable data chunks.
So, we added the .RemoveAll() to our root XElement object and bingo, no more memory leaks! The lesson here is that the XElement is a fully managed object that does not implement IDisposable, so there is no nice way to force it to remove from memory. The .RemoveAll() method at least seems to destroy a lot of the memory footprint of this rather wierd beast.
Hope this helps someone else out!






