xudusheng / gdata-objectivec-client

Automatically exported from code.google.com/p/gdata-objectivec-client
Other
0 stars 0 forks source link

initWithXMLString is leaking #83

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.
Instantiate a GDataXMLElement with initWithXmlString e.g.

  GDataXMLElement* element = [[GDataXMLElement alloc] initWithXMLString:dataString error:&err2];

2.
release the object e.g:
[element release];

What is the expected output?
Element is released and dealloc'ed. 

 What do you see instead?
Element's retain count stays at 1, dealloc never gets called.

I have tried to add the element to a document tree, but to no avail, since the 
element gets copied and the original instance keeps hanging in memory.

MY HACK:
Added a: 

shouldFreeXMLNode_ = YES;

after the element gets copied in initWithXMLString. This takes care of the 
leak. 

What version of the product are you using? On what operating system?

Please provide any additional information below.

Original issue reported on code.google.com by dshimsh...@gmail.com on 3 Jan 2011 at 4:25

GoogleCodeExporter commented 9 years ago
I just tried this with the code snippet

  NSString *str = @"<foo>bar</foo>";
  NSError *err = nil;
  GDataXMLElement* element = [[GDataXMLElement alloc] initWithXMLString:str
                                                                  error:&err];
  [element release];

and set a breakpoint in GDataXMLNode's dealloc method, and the release did lead 
to dealloc being called on the element object. I'm not sure what object you are 
seeing as leaking.

Original comment by grobb...@google.com on 4 Jan 2011 at 9:14

GoogleCodeExporter commented 9 years ago
OK, dealloc is being called but the value of shouldFreeXMLNode_ is NO, hence 
the leak. Attached a capture of Leaks:

Original comment by dshimsh...@gmail.com on 4 Jan 2011 at 10:09

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for pointing this out. Fixed on top-of-trunk.

http://code.google.com/p/gdata-objectivec-client/source/detail?r=614

Original comment by gregrobbins on 4 Jan 2011 at 11:44