You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is an obvious bug in these functions. xmlTextReaderReadOuterXml returns
non-constant xmlChar* which should be released via xmlFree. I had to create my own implementation of these functions in order to avoid memory leak.
Now I need just ~ 400 mb of memory.
Example of corrected inner_xml function
static VALUE inner_xml(VALUE self)
{
xmlTextReaderPtr reader;
Data_Get_Struct(self, xmlTextReader, reader);
xmlChar * value = xmlTextReaderReadInnerXml(reader);
Parsing ~1g xml file I have observed that ruby is using ~5g of memory.
Accidentally I looked at inner_xml and outer_xml functions
static VALUE inner_xml(VALUE self)
{
xmlTextReaderPtr reader;
Data_Get_Struct(self, xmlTextReader, reader);
const char * value = (const char *)xmlTextReaderReadInnerXml(reader);
if(value == NULL)
return Qnil;
else
return NOKOGIRI_STR_NEW2(value);
}
static VALUE outer_xml(VALUE self)
{
xmlTextReaderPtr reader;
Data_Get_Struct(self, xmlTextReader, reader);
const char * value = (const char *)xmlTextReaderReadOuterXml(reader);
if(value == NULL)
return Qnil;
else
return NOKOGIRI_STR_NEW2(value);
}
There is an obvious bug in these functions. xmlTextReaderReadOuterXml returns
non-constant xmlChar* which should be released via xmlFree. I had to create my own implementation of these functions in order to avoid memory leak.
Now I need just ~ 400 mb of memory.
Example of corrected inner_xml function
static VALUE inner_xml(VALUE self)
{
xmlTextReaderPtr reader;
Data_Get_Struct(self, xmlTextReader, reader);
xmlChar * value = xmlTextReaderReadInnerXml(reader);
if(value == NULL)
return Qnil;
else {
VALUE result= rb_str_new2((char*) value);
xmlFree(value);
return result;
}
}
The text was updated successfully, but these errors were encountered: