|
VickyC# wrote:
How can I make sure that the memory is released?
The garbage collector will always release the memory, it's just a question of how long it takes to do so. So long as you've not used any disposable objects and failed to dispose of them, it's a waste of time trying to track memory usage, the framework will collect the objects eventually, and any attempts to mess with it will be counter productive.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Can I force it to release faster?
|
|
|
|
|
Short answer Gc.Collect;. Long answer - don't. The framework has been optimised already, fighting it like this will only hurt performance.
What's the issue, are you running out of memory ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Right now I am not running out of memory. But when the code will go into production I am sure that I will have a high risk to run out of memory.
|
|
|
|
|
VickyC# wrote:
But when the code will go into production I am sure that I will have a high risk to run out of memory.
From opening a few forms ? What's on them ? If it's bitmaps, make sure you dispose of them. If they are just normal forms, are you expecting to run on machines with < 64 MB of memory ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Well here is the pattern, it just keeps tagging some memory and then at some point memory is released but it never reaches the initial amount. So when the app will run for an extendend period of time it seems that I will have an issue. Yes, my question is when a form is disposed do all the children get disposed? Or I need to dispose each one.
|
|
|
|
|
VickyC# wrote:
Well here is the pattern, it just keeps tagging some memory and then at some point memory is released but it never reaches the initial amount. So when the app will run for an extendend period of time it seems that I will have an issue.
You cannot run out of memory, because if things get to a critical level, the framework will force a collectitself. It will also perform a collect periodically. Any objects that are not used for long are quickly cleaned up. Objects that are used for a long time are cached for a long time, which is what you're fighting when you force the collection yourself.
VickyC# wrote:
Yes, my question is when a form is disposed do all the children get disposed? Or I need to dispose each one.
You don't need to dispose of any forms. You only need to dispose of resources such as bitmaps. But yes, if there is an object tree and the object impliments IDisposable, the dispose method should clean all of it.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
|
Christian Graus wrote:
You don't need to dispose of any forms.
Not entirely true. If you call .ShowDialog() on any form, you have to .Dispose() it when you're done with it.
From the MSDN Gospel:
When a form is displayed as a modal dialog box, clicking the close form button (the button with an "X" at the top right of the form) causes the form to be hidden and the DialogResult property to be set to DialogResult.Cancel. Unlike modeless forms, the Close method is not called by the .NET Framework when the user clicks the close form button of a dialog box or sets the value of the DialogResult property. Instead the form is hidden and can be shown again without creating a new instance of the dialog box. Because a form displayed as a dialog box is not closed, you must call the Dispose method of the form when the form is no longer needed by your application.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak wrote:
clicking the close form button (the button with an "X" at the top right of the form) causes the form to be hidden and the DialogResult property to be set to DialogResult.Cancel.
Bloody hell - I didn't know that. How stupid !!! So clicking OK or Cancel will destroy it, but clicking the X does not ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Silly! Isn't it?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks for the tips. I will try your suggestions. I just want to comment that the behavior of C# reminds me applications with embedded languages and the end result is that there is memory leak period.
|
|
|
|
|
How are you dudes ?
i need to display link text near the node name in the tree view and how can i manage its event
thanks alot for your help!!!!
Miss With The Best And Die Like The Rest
|
|
|
|
|
Greetings,
I am writing a toolbar application that I want to dock to the top of the Windows taskbar. I want the form to take up the width of the screen, regardless of resolution. I also want the form to "cut out" the available space for maximized windows. That is, when apps are maximized they stop at the top of my form/toolbar instead of the top of the Windows taskbar (and don't go "underneath" my toolbar).
Any tips on how to accomplish this?
|
|
|
|
|
They are a shell feature called AppBars. Have you tried searching here in CP?
On a quick search, I found this article that looks very good:
http://www.codeproject.com/csharp/csdoesshell3.asp[^]
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005
|
|
|
|
|
Terrific, thanks. I had never heard of "appbars" before. I was searching on "Form.DesktopLocation" and "Form.DesktopBounds" and "Form.Size" and "dockable".
A lot of this is knowing the right word to key in...
|
|
|
|
|
Great! I'm glad I could help!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005
|
|
|
|
|
//Here's some code to draw a line in a Rectangle when a Form1_Paint Event
fires w/ "g.DrawLine(....."
**Problem: If I enter new coordinates into the TextBoxes the old line will not disappear, and I just have line after line drawn on Rect....
What's the fix? Thanks....
//Code to fire on Button Event
private void complexA_OK_Click(object sender, System.EventArgs e)
{
Graphics g = this.CreateGraphics();
Pen cmplxAPen = new Pen(Color.Crimson);
//
try
{
double valAReal;
double valAComplex;
valAReal = Convert.ToDouble(this.textComplexAReal.Text);
valAComplex = Convert.ToDouble(this.textComplexAComplex.Text);
DrawComplexNumber(g, valAReal, valAComplex);
}
catch
{
MessageBox.Show("Invalid Complex A Number", "Error!");
}
}
|
|
|
|
|
You're getting a Graphics object, presemably from the form, but you never .Clear() the canvas before you paint the new line.
You really should be doing the majority, if not ALL, of your drawing in the form's Paint event. You can see why if you just enter one set of numbers into your app, then drag your window so that nearly the entire window is off the bottom of the screen, then drag it back up. Your form's blank again, isn't it? You have to repaint it whenever Windows throws a WM_PAINT message your way.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Suppose we have that part of code:
for(...)
{
foreach(...)
{
if (...)
{
while(...)
{
<big>-> XXX <-</big>
}
}
}
}
how am I supposed to exit from the place 'XXX' so that I would 'land' outside (after) the most internal ('for') loop?
|
|
|
|
|
One way would be to turn that code into it's own subroutine and use return; to break the process and close the subroutine
|
|
|
|
|
Yoyosch wrote:
how am I supposed to exit from the place 'XXX' so that I would 'land' outside (after) the most internal ('for') loop?
Use goto
for(...)
{
foreach(...)
{
if (...)
{
while(...)
{
goto Gotcha;
}
}
}
}
Gotcha:
Console.WriteLine("Gotcha");
Andres Manggini.
Buenos Aires - Argentina.
|
|
|
|
|
this is surely fastest way but is recognazed as extremaly nasty... there is no other way (line using several break;`s ?)
|
|
|
|
|
|
[code]
bool error = false;
for(...)
{
foreach(...)
{
if (...)
{
while(...)
{
//-> XXX <-
error = true;
break;
}
}
if (error)
break;
}
if (error)
break;
}
[/code]
|
|
|
|