Improve memory usage

I want to reduce memory usage, in the save method of the psd, it is where it consumes a lot of memory. How can I limit memory usage to a certain number? I have tried the following:

            Cache.CacheType = CacheType.CacheInMemoryOnly;
            Cache.MaxMemoryForCache = 1073741824;// 1 gigabyte
            long l1 = Cache.AllocatedDiskBytesCount;
            long l2 = Cache.AllocatedMemoryBytesCount;

            //load psd file
            PsdImage image = (PsdImage)Image.Load("C:\\psd_example.psd");
            if (!image.IsCached)
            {
                image.CacheData();
            }
        
            image.Save("C:\\psd_output");
            long diskBytes = Cache.AllocatedDiskBytesCount;
            long memoryBytes = Cache.AllocatedMemoryBytesCount; 
            l1 = Cache.AllocatedDiskBytesCount;
            l2 = Cache.AllocatedMemoryBytesCount;

Psd used:
psd_used.zip (268 Bytes)

@cristianortegaethofy
Thank for the idea. We have some plans on 2024 on RAM usage optimization. But at this moment Aspose.PSD uses maximum available memory if this is not enough than it starts partial processing. But for the case with big files, any available RAM will be not enough, so this feature can be useful.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PSDNET-1826

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@Dmitriy.Sorokin Ok, couldn’t memory use be optimized with the Cache class or what would this be for?

@cristianortegaethofy I created additional investigation task for it. We plan optimizing of RAM usage on 23.3-23.4

PSDNET-1829: Investigate ability to use Disk Memory instead of RAM for processing of PSD Images

@Dmitriy.Sorokin Ok, I wait for the investigation task, if it is possible with cache class or the way to use Disk Memory instead of RAM, thank you

Hi @Dmitriy.Sorokin I come again to ask you if there is any news. Can we optimize memory usage with the cache class?

@cristianortegaethofy This task is planned for 2024. There are no news at the moment. If one of the developers becomes available, we will try to do it faster.

@Dmitriy.Sorokin I wanted to know how the planning or progress is going, thank you

@cristianortegaethofy this task is one of the main on 2024/Q1. Aspose.PSD team will start work on optimization soon.

1 Like