I am learning a lot about memory management but this one problem has me wondering.
In a class method I create a variable:
TBXMLElement *pieceXML = [TBXML childElementNamed:@"piece"
parentElement:rootElement];
And the release it at the end of the method:
[pieceXML release];
But I get the error: Invalid receiver type 'TBXMLElement *'
The implemenation of childElementNamed:parentElement: is below
+ (TBXMLElement*) childElementNamed:(NSString*)aName parentElement:(TBXMLElement*)aParentXMLElement{
TBXMLElement * xmlElement = aParentXMLElement->firstChild;
const char * name = [aName cStringUsingEncoding:NSUTF8StringEncoding];
while (xmlElement) {
if (strlen(xmlElement->name) == strlen(name) && memcmp(xmlElement->name,name,strlen(name)) == 0) {
return xmlElement;
}
xmlElement = xmlElement->nextSibling;
}
return nil;
}
I am trying to understand how I can predict this happening again and any references to reading is welcome since I am not sure how to find the reason for this even after looking.
Thanks.
TBXMLElementis not an Objective-C class — it’s a Cstructinstead.This means that
pieceXMLis not an Objective-C object, hence you cannot send it any Objective-C messages. In particular, you cannot send it-release.