Does Point Class accumulate Ram Memory with each New C #?

0

I have a problem. I'm doing a simple game which consists of moving a picturebox every time I press a key and to move the PictureBox I use:

pictureBox1.Location = new Point(pictureBox1.Location.X+10, pictureBox1.Location.Y);

And I've noticed that while moving my pictureBox in the form the application consumes more and more ram memory, I guess that is because many New Point is made. Please someone help me solve this problem?

    
asked by Javier 04.02.2018 в 18:28
source

1 answer

0

I do not know to what extent the increase in memory is due to the creation of the points, but it occurs to me that you can set a Point type variable, modify it and assign it to the PictureBox each time you press a key. Something like this:

// Esto iría a nivel de clase...
Point Punto = new Point(xInicial, yInicial);

// Al pulsar una tecla iría esto...
Punto.X += 10;
pictureBox1.Location = Punto;

In this way you would reuse the Point object in each movement without generating a new point each time, although because Point is a structure and I think it is immutable, the memory problem could remain the same, since a new one is generated Point object when modifying a value of it.

Greetings.

    
answered by 05.02.2018 / 08:47
source