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

Free Support Forum - aspose.com

Microsoft C++ Exception : std:bad_alloc in many pages' saving

I want to save 10,000 pages to a PDF file using Aspose.PDF.C++.

10000 pages -> 1 file : at once
But, raise exception (Microsoft C++ Exception : std:bad_alloc)

So, I fixed (1 page -> 1 same file) X 10000 times
But, I got a same result.

What should I do?


Can you please share complete working sample code along with source file to further investigate this issue in details.

Here is a sample code.

auto doc = MakeObject<Aspose::Pdf::Document>();

for (int i = 0; i < 30000; i++){
auto page = doc->get_Pages()->Add();
auto table = MakeObject<Aspose::Pdf::Table>();

for (int j = 0; j < 20; j++)
	auto row = table->get_Rows()->Add();
	auto cells = row->get_Cells();
auto paragraps = page->get_Paragraphs();
paragraps->Add(MakeObject<TextFragment>(u"Sample Code"));
paragraps->Add(MakeObject<TextFragment>(String::Format(u"{0} Page", i + 1)));

auto border = MakeObject<BorderInfo>(Aspose::Pdf::BorderSide::All, 0.1, Color::FromRgb(System::Drawing::Color::get_Black()));
border = MakeObject<BorderInfo>(Aspose::Pdf::BorderSide::Box, 1, Color::FromRgb(System::Drawing::Color::get_Black()));



while program running, a process memory has increased.
If you run successfully, increase i repeat time.


Thanks for sharing further details.

We have logged an investigation ticket as PDFCPP-1221 in our issue tracking system. We will further look into details of it and keep you posted with the status of its resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.

I found a problem.

paragraps->Add(MakeObject<TextFragment>(u"Sample Code"));
paragraps->Add(MakeObject<TextFragment>(String::Format(u"{0} Page", i + 1)));

An allocated memory in MakeObject<TextFragment> is not free when Aspose::Pdf::Document’s object is free.
Please could you fix it?


Thanks for sharing this information. I have mentioned this in ticket and we will share good news with you soon.