Group: Forum Members
Posts: 1,
Visits: 1
|
We've run into the same sort of OutOfMemoryExceptions when using large images... in our case, inside objects rather than as the background. Here's our analysis so far:
(1) Nevron doesn't seem to be designed to handle normal-size bitmaps... the only apparent mechanism appears to be designed for tiny bitmaps used as Brush textures. So (I say this reluctantly since we've invested a lot in Nevron-based code), it may not be the right library if you need to use normal-size photographs in the diagrams.
(2) Based on examining what's produced in a Memory Profiler, it appears that creating an NImageFillStyle from a Bitmap creates a copy of that Bitmap from which it builds a new Brush... and it puts that Bitmap-Brush pair into an internal Hashtable. Those never get removed.
(3) The View and the Zoom Preview each seem to end up with their own Bitmap objects... painted using the Brush, we presume... so, probably separate Bitmaps. Those do seem to go away when you make changes.
One question we had was whether that Hashtable is testing the key Bitmaps by-reference or by-value. Given you are having trouble with that code, the answer must be by-reference.
Based on that analysis, since you are always setting the background to either nothing, the male pic, or the female pic, a possible solution for you is to create the two Bitmaps, create two NImageFillStyles from those, and never Dispose and reload any of those. Then just swap between the different NImageFillStyles... so, presumably Nevron will then find the matching Brush rather than rebuild it, and then reuse those elements rather than accumulating new ones.
Another thing you should do is make sure that the .png and the .jpg images are only as high resolution as you need on-screen... because the Bitmaps' sizes will be dictated by the uncompressed pixel array it generates (the resolution of those files, not the megabytes of those files).
Please let us know if that works for you... it won't solve our problem, but it will close some knowledge gaps in our analysis. Hope that helps.
|