Which one is the optimal way of creating Workbook object that requires less java heap space

Hello Aspose Team,

Which one is the optimal way of creating Workbook object that requires less java heap space?
As I see multiple ways
#1 workbook = new AsposeWorkbook(filepath);

#2

System.IO.FileStream fstream = new System.IO.FileStream(filepath, FileMode.Open);

LoadOptions loadOptions = new LoadOptions(LoadFormat.Xlsx);//or other file formats also

Workbook workbook = new Workbook(fstream, loadOptions);

fstream.Dispose();

#3

FileStream fs = File.Open(filepath,FileMode.Open);

byte[] buffer = new byte[fs.Length];

fs.Read(buffer, 0, buffer.Length);

MemoryStream ms = new MemoryStream(buffer);

LoadOptions loadOptions = new LoadOptions(LoadFormat.Xlsx);//or other file formats also

Workbook workbook = new Workbook(ms, loadOptions);

Thanks in advance.

Rita Patel

Hi,

Thanks for your posting and using Aspose.Cells for Java.

Well, the internal mechanism of creating template file is same, so it will not affect your heap space. However, some of these methods are better than others according to your situation.

For example, if you are using the direct file path, then your code will be simplified but you will have less control on disposing it.

But if you will use the file stream, then you will have the flexibility of closing the stream as per your needs.

Similarly, if you use the memory stream, then you will have the flexibility of creating documents without hitting your hard drive for reading/writing. It will use the RAM for the purpose of creation or manipulation of documents.

Besides, the code you pasted is not Java but C#. I will recommend you to see the following articles for your further help.


Besides, you should download and use the latest offline demos of both C# and Java for your more help. These demos will make you familiar of Aspose.Cells API(s) quickly and these demos are very simple and can be run easily.


Hi,

Thanks for replying to my question. So does that means regardless of file size (e.g. 1MB file or 126MB etc..) of the existing excel (any file format) any of that 3 option's internal mechanism is same and java heap should not be affected? As I am trying to optimize our application's code which requires to read the file provided by end user and work with that data. So appreciate your assistance.

Thanks again,
Rita.

Hi,

Thanks for replying to my question. So does that means regardless of file size (e.g. 1MB file or 126MB etc..) of the existing excel (any file format) any of that 3 option's internal mechanism is same and java heap should not be affected?

Also could you give couple of examples in regards what method is good in what situation?(As per your comment... "However, some of these methods are better than others according to your situation.")

As I am trying to optimize our application's code which requires to read the file provided by end user and work with that data. We appreciate your assistance.

Thanks again,
Rita.

RNP:

Hi,

Thanks for replying to my question. So does that means regardless of file size (e.g. 1MB file or 126MB etc..) of the existing excel (any file format) any of that 3 option's internal mechanism is same and java heap should not be affected? As I am trying to optimize our application's code which requires to read the file provided by end user and work with that data. So appreciate your assistance.

Thanks again,
Rita.

Hi,

Thanks for your posting and using Aspose.Cells for Java.

Definitely, larger sized file will take more heap space. Because larger file will have larger number of objects or larger sized objects.

However, internal mechanism of loading file is actually same. Besides, we will look into your issue further and advise you asap.
RNP:

Hi,

Thanks for replying to my question. So does that means regardless of file size (e.g. 1MB file or 126MB etc..) of the existing excel (any file format) any of that 3 option's internal mechanism is same and java heap should not be affected?

Also could you give couple of examples in regards what method is good in what situation?(As per your comment... "However, some of these methods are better than others according to your situation.")

As I am trying to optimize our application's code which requires to read the file provided by end user and work with that data. We appreciate your assistance.

Thanks again,
Rita.



Hi,

Thanks for your posting and using Aspose.Cells for Java.

For memory usage consideration, it is better for users to use the way #1 for all situations when possible.

#2 has less flexibility than #1 but has no obvious difference of memory cost from #1 for Aspose.Cell for .Net version for most situations. However, for Java version, because common FileInputStream cannot be accessed randomly, buffer must be created to cache the file data when needed. In such situation #2 will given same memory cost with #3.

For #3, you can see obviously extra memory needs to be used for the cached file data(buffer array).

So, we recommend users to prefer #1 for all situations than other two ways when using file is available.