Fix string leaking (and destructors not getting called) when there are XMLNodes that aren't in the document tree
diff --git a/tinyxml2.h b/tinyxml2.h
index 94c9c6f..a740dc3 100755
--- a/tinyxml2.h
+++ b/tinyxml2.h
@@ -264,6 +264,12 @@
         return _allocated;

     }

 

+	void SwapRemove(int i) {

+		TIXMLASSERT(i < _size);

+		_mem[i] = _mem[_size - 1];

+		--_size;

+	}

+

     const T* Mem() const				{

         TIXMLASSERT( _mem );

         return _mem;

@@ -1802,6 +1808,9 @@
     // internal

     char* Identify( char* p, XMLNode** node );

 

+	// internal

+	void MarkInUse(XMLNode*);

+

     virtual XMLNode* ShallowClone( XMLDocument* /*document*/ ) const	{

         return 0;

     }

@@ -1822,6 +1831,13 @@
     int             _errorLineNum;

     char*			_charBuffer;

     int				_parseCurLineNum;

+	// Memory tracking does add some overhead.

+	// However, the code assumes that you don't

+	// have a bunch of unlinked nodes around.

+	// Therefore it takes less memory to track

+	// in the document vs. a linked list in the XMLNode,

+	// and the performance is the same.

+	DynArray<XMLNode*, 10> _unlinked;

 

     MemPoolT< sizeof(XMLElement) >	 _elementPool;

     MemPoolT< sizeof(XMLAttribute) > _attributePool;

@@ -1844,6 +1860,8 @@
     NodeType* returnNode = new (pool.Alloc()) NodeType( this );

     TIXMLASSERT( returnNode );

     returnNode->_memPool = &pool;

+

+	_unlinked.Push(returnNode);

     return returnNode;

 }