GregJ7
Member
- Joined
- Nov 23, 2024
- Messages
- 20
- Programming Experience
- 10+
Am I correct in thinking that the object line will not be allocated on the stack, because the compiler recognizes that myCanvas.Children.Add(line) only passes a reference to the line and must not be popped off the stack when the function exits?
If I am being dumb, then my question really is, do I need to keep a copy of objects (Lines) in memory that I add to the Canvas.Children collection, because Add() does not copy the line information, but only a reference, which will be needed when the lines are redrawn (such as if the window is resized)?
Thanks.
C#:
// concept code, not tested
public void MyAddLine(float x1, float y1, float x2, float y2)
{
Line line;
line.Visibility = Visibility.Visible;
line.StrokeThickness = 1;
line.Stroke = Brushes.Orange;
line.X1 = x1;
line.Y1 = y1;
line.X2 = x2;
line.Y2 = y2;
myCanvas.Children.Add(line);
Thanks.