0

In Winforms project, I have a collection of Bitmap (List of Bitmap) and I am adding Bitmap files into this collection.
At some point of time this List gets automatically reduced by GC, this way I am loosing data whenever Garbage Collector runs.
I referred this post and included the Global List variable into GC.AddMemoryPressure but still GC is removing most of the data from List variable.
How to make sure that my big List of Bitmap stays unchanged on memory for longer duration?

Abhay Dixit
  • 998
  • 8
  • 28
Prakash M
  • 659
  • 1
  • 12
  • 36
  • GC should not affect a `List` nor its contents as long as you have a live reference on it. However, if you loaded the bitmaps from a file or Stream, you may have a problem from their own lifetime management. – Medinoc Aug 14 '17 at 12:17
  • i'm loading Bitmap from camera input, at no particular time, when `GC` runs i see that memory consumption gets reduced by almost half (if 2gb ram is used, after `GC` runs then it comes down to 1gb) – Prakash M Aug 14 '17 at 13:28
  • 1
    That's because non-contiguous data is moved around, eliminating gaps, and that way memory pages can be freed. You're not losing data (but if you have unmanaged pointers to your bitmaps' data, these pointers can be left dangling). – Medinoc Aug 16 '17 at 15:05

0 Answers0