I'm building an application (WPF) and I have a Panel in the
application which will be populated dynamically with objects of the
type Grid, TextBox, etc. For simplicity, let's say I'm just adding and
deleting Grid objects. I can add the objects easily by creating Grid
objects. The problem I have is that I don't know how to delete the
objects. How do you delete a Grid object? I'd prefer to not have to
turn the "visible" switch off and wait for the garbage collector to
come around.
Any ideas? 11 2832
Turning the visible switch will not cause the GC to collect the object.
It will just set the visibility of the control to false, as the reference to
the object will still be held by the parent object.
I also don't know how you are using a Panel, and not a derived class, as
Panel is marked abstract.
Regardless, any class that derives from Panel that you are using has a
Children property which has all the child controls that are on the panel.
Pass your Grid to the Remove method on the UIElementCollection that is
exposed through the Children property and it will be removed.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
<do********@hotmail.comwrote in message
news:11**********************@19g2000hsx.googlegro ups.com...
I'm building an application (WPF) and I have a Panel in the
application which will be populated dynamically with objects of the
type Grid, TextBox, etc. For simplicity, let's say I'm just adding and
deleting Grid objects. I can add the objects easily by creating Grid
objects. The problem I have is that I don't know how to delete the
objects. How do you delete a Grid object? I'd prefer to not have to
turn the "visible" switch off and wait for the garbage collector to
come around.
Any ideas?
<do********@hotmail.comwrote in message
news:11**********************@19g2000hsx.googlegro ups.com...
I'm building an application (WPF) and I have a Panel in the
application which will be populated dynamically with objects of the
type Grid, TextBox, etc. For simplicity, let's say I'm just adding and
deleting Grid objects. I can add the objects easily by creating Grid
objects. The problem I have is that I don't know how to delete the
objects.
How do you delete a Grid object? I'd prefer to not have to
turn the "visible" switch off and wait for the garbage collector to
come around.
You always have to wait for the garbage collector to come around; you can't
deallocate memory explicitly in .NET .. in any case, making an object not
visible doesn't mark it for garbage collection, it makes it not visible
Can't say I've ever done what you're doing but can't you just grid.Dispose()
it?
Liz wrote:
<do********@hotmail.comwrote in message
news:11**********************@19g2000hsx.googlegro ups.com...
>I'm building an application (WPF) and I have a Panel in the application which will be populated dynamically with objects of the type Grid, TextBox, etc. For simplicity, let's say I'm just adding and deleting Grid objects. I can add the objects easily by creating Grid objects. The problem I have is that I don't know how to delete the objects.
>How do you delete a Grid object? I'd prefer to not have to turn the "visible" switch off and wait for the garbage collector to come around.
You always have to wait for the garbage collector to come around;
That's not entirely true. You can use stackalloc to allocate memory on
the stack (away from the garbage collector).
It's good if you frequently need to allocate moderately large arrays of
objects. Garbage collection hurts in that situation.
Alun Harford
"Alun Harford" <de*****@alunharford.co.ukwrote in message
news:OD**************@TK2MSFTNGP03.phx.gbl...
Liz wrote:
>> You always have to wait for the garbage collector to come around;
That's not entirely true. You can use stackalloc to allocate memory on the
stack (away from the garbage collector).
It's good if you frequently need to allocate moderately large arrays of
objects. Garbage collection hurts in that situation.
glad you mentioned stackalloc, Alun ... it is useful and too often ignored
(or so it seems); so I'll rephrase and say you always have to wait for the
GC where the GC is capable of doing anything ... certainly the OP has no
choice but to wait for it with respect to his dynamically instantiated grids
I kind of don't see the point of mentioning this, as you can't allocate
pointers to reference type arrays using stackalloc. You can only use value
types.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Liz" <li*@tiredofspam.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>
"Alun Harford" <de*****@alunharford.co.ukwrote in message
news:OD**************@TK2MSFTNGP03.phx.gbl...
>Liz wrote:
>>> You always have to wait for the garbage collector to come around;
>That's not entirely true. You can use stackalloc to allocate memory on the stack (away from the garbage collector).
It's good if you frequently need to allocate moderately large arrays of objects. Garbage collection hurts in that situation.
glad you mentioned stackalloc, Alun ... it is useful and too often ignored
(or so it seems); so I'll rephrase and say you always have to wait for
the GC where the GC is capable of doing anything ... certainly the OP has
no choice but to wait for it with respect to his dynamically instantiated
grids
Controls in WPF do not implement IDisposable, so this isn't a feasible
solution.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Liz" <li*@tiredofspam.comwrote in message
news:eY*************@TK2MSFTNGP06.phx.gbl...
>
<do********@hotmail.comwrote in message
news:11**********************@19g2000hsx.googlegro ups.com...
>I'm building an application (WPF) and I have a Panel in the application which will be populated dynamically with objects of the type Grid, TextBox, etc. For simplicity, let's say I'm just adding and deleting Grid objects. I can add the objects easily by creating Grid objects. The problem I have is that I don't know how to delete the objects.
>How do you delete a Grid object? I'd prefer to not have to turn the "visible" switch off and wait for the garbage collector to come around.
You always have to wait for the garbage collector to come around; you
can't deallocate memory explicitly in .NET .. in any case, making an
object not visible doesn't mark it for garbage collection, it makes it not
visible
Can't say I've ever done what you're doing but can't you just
grid.Dispose() it?
Nicholas Paldino [.NET/C# MVP] wrote:
I kind of don't see the point of mentioning this, as you can't
allocate pointers to reference type arrays using stackalloc. You can
only use value types.
I just didn't want people to think .NET/C# is a inherrently slow. In
situations where GC is very bad, you *can* avoid it (if you really must).
Alun Harford
Alun,
That's the thing, unless you are going to use value types for
everything, then no, you are not going to be able to avoid GC. Even in
IDisposable implementations, you might be able to eliminate the chance of
^finalization^ occuring, the object itself is still subject to garbage
collection. You can't avoid it for reference types.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Alun Harford" <de*****@alunharford.co.ukwrote in message
news:eu**************@TK2MSFTNGP04.phx.gbl...
Nicholas Paldino [.NET/C# MVP] wrote:
> I kind of don't see the point of mentioning this, as you can't allocate pointers to reference type arrays using stackalloc. You can only use value types.
I just didn't want people to think .NET/C# is a inherrently slow. In
situations where GC is very bad, you *can* avoid it (if you really must).
Alun Harford
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:ub**************@TK2MSFTNGP06.phx.gbl...
Controls in WPF do not implement IDisposable, so this isn't a feasible
solution.
didn't know that ... so what do we do in WPF? grid = null; ??
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Liz" <li*@tiredofspam.comwrote in message
news:eY*************@TK2MSFTNGP06.phx.gbl...
>> <do********@hotmail.comwrote in message news:11**********************@19g2000hsx.googlegr oups.com...
>>I'm building an application (WPF) and I have a Panel in the application which will be populated dynamically with objects of the type Grid, TextBox, etc. For simplicity, let's say I'm just adding and deleting Grid objects. I can add the objects easily by creating Grid objects. The problem I have is that I don't know how to delete the objects.
>>How do you delete a Grid object? I'd prefer to not have to turn the "visible" switch off and wait for the garbage collector to come around.
You always have to wait for the garbage collector to come around; you can't deallocate memory explicitly in .NET .. in any case, making an object not visible doesn't mark it for garbage collection, it makes it not visible
Can't say I've ever done what you're doing but can't you just grid.Dispose() it?
On Nov 10, 2:22 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
Turning the visible switch will not cause the GC to collect the object.
It will just set the visibility of the control to false, as the reference to
the object will still be held by the parent object.
I also don't know how you are using a Panel, and not a derived class, as
Panel is marked abstract.
Regardless, any class that derives from Panel that you are using has a
Children property which has all the child controls that are on the panel.
Pass your Grid to the Remove method on the UIElementCollection that is
exposed through the Children property and it will be removed.
--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com
Thanks,
<parent Control>.Children.Remove(UIElement) did what I wanted.
Regards,
D
See my original response for the answer.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Liz" <li*@tiredofspam.comwrote in message
news:uA*************@TK2MSFTNGP06.phx.gbl...
>
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:ub**************@TK2MSFTNGP06.phx.gbl...
>Controls in WPF do not implement IDisposable, so this isn't a feasible solution.
didn't know that ... so what do we do in WPF? grid = null; ??
>-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Liz" <li*@tiredofspam.comwrote in message news:eY*************@TK2MSFTNGP06.phx.gbl...
>>> <do********@hotmail.comwrote in message news:11**********************@19g2000hsx.googleg roups.com...
I'm building an application (WPF) and I have a Panel in the application which will be populated dynamically with objects of the type Grid, TextBox, etc. For simplicity, let's say I'm just adding and deleting Grid objects. I can add the objects easily by creating Grid objects. The problem I have is that I don't know how to delete the objects.
How do you delete a Grid object? I'd prefer to not have to turn the "visible" switch off and wait for the garbage collector to come around.
You always have to wait for the garbage collector to come around; you can't deallocate memory explicitly in .NET .. in any case, making an object not visible doesn't mark it for garbage collection, it makes it not visible
Can't say I've ever done what you're doing but can't you just grid.Dispose() it? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Stephen |
last post by:
I have got an event below to remove items from an arraylist and then to
rebind the arraylist to the datagrid subsequently deleting the appropriate
row. My problem is that my code makes sense and I...
|
by: enki |
last post by:
I am writing a game and I am having trouble with moving the character
on the map.
Here is what I have right now. It involves win32 programming but that
not my problem. I would like some...
|
by: simon |
last post by:
I have one question.
DataGrid control is performance cost.Use any other control if possible. That
is by the book.
But I need sorting and paging on all my pages.
So, is there any better...
|
by: z. f. |
last post by:
Hi,
i stated that this is an advanced question because i have a post from few
days ago that i received answers to with suggestions that looked good but
did not work, so please if you post a...
|
by: Paul |
last post by:
Hi I have 2 data grids and several controls on a web page. The grids will
vary in size, just wondering if the lower grid could be covered by part of
the upper grid depending on its size or is there...
|
by: vcornjamb |
last post by:
Hello, I am developing a web form that contains some buttons and a data grid
which has as its last column link buttons that will delete the data
associated
with that row. Everything works fine,...
|
by: Frank |
last post by:
Hello,
I am developing with VS.Net 2003 on the asp 1.1 platform.
I am a few days new to using a datagrid. I found a nice tutorial and had no
problems using an editable datagrid with textboxes...
|
by: Terry Holland |
last post by:
I have an asp page that contains a user control. This control is a panel
containing a number of link buttons that get displayed if certain conditions
in the db are met and these conditions can...
|
by: Kiran |
last post by:
Hello All,
I created a grid, where I register events every time the user changes
an existing value inside the grid control. Right now, I am using the
event: EVT_GRID_CELL_CHANGE. However, I...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |