using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Syncfusion.EJ2.DocumentEditor;
namespace Test.Controllers
{
[ApiController]
[Route("[controller]")]
public class SfdtController : ControllerBase
{
[HttpPost]
[Route("docx")]
public IActionResult Test([FromBody] Input input)
{
foreach (var sfdt in input.Content)
{
using var stream =
WordDocument.Save(sfdt, FormatType.Docx);
}
return Content("");
}
public class Input
{
public ICollection<string> Content { get; set; }
}
}
}
Either the is a memory leak somewhere or we're handling sfdt documents incorrectly, either way some advice would be helpful.|
stream.Dispose();
document.Dispose();
fileStream.Close(); |
I would like to confirm that there is 100% a leak in the SF code here. I have a piece of code that just converts an sfdt string to a word document and then instantly closes and disposes of the word doc and every time this piece of code is run it adds another 200mb of overhead to my memory usage. Code is below. Also this editor has decided it do
string sfdtText = "";using (Stream docStream = _docStorageProvider.LoadDocument(section.FileId)){using (StreamReader reader = new StreamReader(docStream, Encoding.UTF8)){sfdtText = reader.ReadToEnd();}}
#warning possible memory leak//SFDT to .docxvar wordDoc = Syncfusion.EJ2.DocumentEditor.WordDocument.Save(sfdtText);wordDoc.Close();wordDoc.Dispose();
I can confirm that i am using version 19.2.0.57.
I can also confirm that this issue can happen with many documents but the easiest way to recreate it and the one that creates the most obvious leak is to create a sfdt file with a large image in it and then try to convert that to a word file using the method from my previous comment. To be specific i used this image https://images.hdqwalls.com/download/moon-stars-dark-10k-d3-7680x4320.jpg converting that file caused me to go from about 200mb of memory usage to 1.2GB and then the usage will steadily rise at a much slower pace if the process is repeated
Also i cannot share the original file used as it contains confidential conf