We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Release Memory used by Document Instance when Scope Ends to Prevent Memory Leak in Aspose.Words for C++

Perhaps I don’t understand how to use SharedPtr and MakeObject, but the Visual Studio resource monitor shows this code using up lots of memory as it runs:

#include <Aspose.Words.Cpp/Model/Document/Document.h>

using namespace Aspose::Words;
using namespace Aspose::Words::Saving;

int main()
	System::SharedPtr<Document> doc;

	while ( true )
		doc = System::MakeObject<Document>( System::String( "My Doc In.docx" ) );
		doc->Save( System::String( "My Doc Out.docx" ) );

I have a library using Aspose.Words that uses a single Document object. In regular C++, I would normally delete the Document object, but delete doesn’t work on SharedPtr. Whenever I open a new document into that object, it seems like the old document is never removed from memory. Please help!


We tested the scenario and have managed to reproduce the same problem on our end. For the sake of correction, we have logged this problem in our issue tracking system. The ID of this issue is WORDSCPP-934. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.

1 Like


It is to update you that the issue you have found earlier (filed as WORDSCPP-934) has been fixed in this Aspose.Words for C++ 20.3 update. So, please upgrade to the latest version of Aspose.Words for C++ API. Hope, this helps.