Hello, Aspose!
Question about life cycle of Aspose.Pdf.Document that created from stream.
I have a factory of pdf documents (> 300 documents in memory):
public class DocumentFactory : IDocumentFactory
{
public Task<Aspose.Pdf.Document> Create(Stream stream)
{
return Task.Run(() =>
{
return new Aspose.Pdf.Document(stream);
});
}
}
I create all documents on app startup like that:
public async Task<Aspose.Pdf.Document> CreateDocument(IDocumentFactory factory, byte[] bytes)
{
var stream = new MemoryStream(bytes));
var document = await factory.Create(stream);
return document;
}
And after that i will use created documents in my application every ~5 minutes.
All works perfectly, but my question about potential memory leak while creation from stream object:
Should i dispose stream instantly after i create Aspose.Pdf.Document like in code below?
public async Task<Aspose.Pdf.Document> CreateDocument(IDocumentFactory factory, byte[] bytes)
{
Aspose.Pdf.Document document;
using(var stream = new MemoryStream(bytes))
{
document = await factory.Create(stream);
}
return document;
}
Or Aspose.Pdf.Document use provided stream in all life cycle of document and throw ObjectDisposedException when i trying to access to document fields or methods?
If not, should i manually dispose stream object when i remove old document from memory?