Tiago Pasqualini
Tiago Pasqualini

Reputation: 821

BitmapData allocates a lot of memory when created

I have an application which manipulates high resolution images (something around 100+ megapixels), and I'm having some memory issues. When the BitmapData object is created, it allocates memory to store this image. The problem, is that I already have a ByteArray with this image's pixels (which have something around 400+ MB), so when the BitmapData is created, it allocates memory to store the same data that I have on the ByteArray.

After its creation, I can set the pixels from the ByteArray to the BitmapData and free the ByteArray. But this memory peak is, sometimes, causing the runtime to raise an exception, telling that the system is out of memory.

Is there any way to tell the BitmapData to use my own ByteArray? Or any other solution that I don't have to use double the memory that I need?

Upvotes: 1

Views: 463

Answers (1)

Tiago Pasqualini
Tiago Pasqualini

Reputation: 821

In case anyone needs this, here's what I did:

I get the ByteArray, which contains the pixels of the image, from a socket. I read these pixels from the sockets in tiny parts, so I, instead of waiting for the whole image to be loaded from the socket, I put these small parts directly into the BitmapData. This prevents the application to allocate double the memory I actually need.

Upvotes: 1

Related Questions