Bug #69082 | Connector/NET introduces memory leak after an XmlSerializer has been instanced | ||
---|---|---|---|
Submitted: | 26 Apr 2013 11:36 | Modified: | 3 Jun 2013 6:17 |
Reporter: | Juergen Steinblock | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | Connector / NET | Severity: | S3 (Non-critical) |
Version: | 6.6.5.0 | OS: | Windows (7 x64 / 2008 x64) |
Assigned to: | Francisco Alberto Tirado Zavala | CPU Architecture: | Any |
Tags: | xmlserializer memory-leak |
[26 Apr 2013 11:36]
Juergen Steinblock
[31 May 2013 23:32]
Francisco Alberto Tirado Zavala
Hello. The issue that you reported is not related with Connector/Net but it is a XmlSerializer bug related with the class constructor. You can read something about it in the following link: http://msdn.microsoft.com/en-us/magazine/cc163491.aspx#S4 You can find the info in the "Leaking Unmanaged Heap Memory" section of the link. I did a little change to the VB code you posted (pass a XmlRootAttribute to XmlSerializer constructor), and the issue dissapear: Imports System.Xml.Serialization Imports MySql.Data.MySqlClient Public Class Pool End Class Module MemoryLeakRevision Sub Main() Dim serializer As _ New XmlSerializer(GetType(Pool), New XmlRootAttribute("Pool")) Dim counter As Integer = 1 Do Dim result As Object = MySqlHelper.ExecuteScalar("Server=localhost;Port=3305;uid=root", "SELECT NOW()", Nothing) Console.WriteLine("{0} {1,10} | Counter:{2}", result, Environment.WorkingSet, counter) counter += 1 Loop End Sub End Module Please see an image that I attached on files section where you can see the behaviour after the change I did. In the image you can appreciate that the counter loop is over 560k and the memory issue is not present. Saludos and happy coding Francisco Tirado
[31 May 2013 23:32]
Francisco Alberto Tirado Zavala
MySQL-VB Memory Leak Revision
Attachment: MySQL-VB Memory Leak Revision.jpg (image/jpeg, text), 293.13 KiB.
[3 Jun 2013 6:17]
Juergen Steinblock
Hello Francisco, I was aware about XmlSerializer containing a memory leak because I read some discussions about it before posting here. But I thought they wouldn't apply because the are all like "XmlSerializer will create a dynamic assembly at runtime and load it in your app domain everytime you create a new instance" and I only create one instance and never really use the serializer at runtime. I verified that the code change (use the overload) works and no memory is leaking anymore. According to the link you provided, this seems to be the most plausible cause (Somewhere a finalizer does not complete and prevents other finalizers from running their cleanup code). > If that misbehaving finalizer erroneously tries over and over again > to access the database, never returning, the "well-behaved" finalizer will > never get a chance to run.
[3 Jun 2013 16:31]
Francisco Alberto Tirado Zavala
Basis on the documentation some constructors has the problem with the memory leak but not all, the issue will depends on the constructor used besides the class attributes configuration. After some research and try to get more information about XmlSerializer best practices or known issues, I found the following information for troubleshooting: http://msdn.microsoft.com/en-us/library/aa302290.aspx I tried to figure out if there is a relation with connections to DB's and XmlSerializer, but I had no luck with that.