I’m a new programmer and I just come up with a question of memory leakage. Am I leaking memory if I declare a variable in a loop to make it be declared again and again?
For example, I have
while(true)
{
Image<Gray, Byte> MyImage = new Image<Gray, Byte> (1024, 768);
//do something else
}
I know it’s an infinite loop but my question is about the memory. Is the memory usage growing fast in this loop? Should I release MyImage manually?
You need to call
MyImage.Dispose()after using it.Another way is to change the code to: