I'm writing an image processing app. The algo is like this: First, I load a set of background images (~1.5 Mb each) either from local cache or from the Internet. Then I download multiple foreground images (~ 1Mb each), scale them an draw upon each bg image.
I load all bg images and keep them in memory (they all go to LOH) while all foreground images are being processed.
The code runs in multiple threads and currenly I'm using byte arrays to store images and covert them to Bitmaps only when using drawing methods.
The thing is that there are multiple LOH segments created to store large byte arrays. They take pretty much memory and GC does not seem to collect it after processing is done. When a new request arrives, another set of bg images is loaded into memory (LOH) and so on.
I thought about pooling arrays but it is not appicable in my app, I think.
So my question is how to manage large images/byte array and avoid LOH fragmentation?