Click here to Skip to main content
15,923,006 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to Prevent decompile or dis-assembly c# project (.NET)? Pin
Heath Stewart7-Jul-04 5:17
protectorHeath Stewart7-Jul-04 5:17 
Answernot only you that face this problem :) Pin
Hesham Amin7-Jul-04 4:18
Hesham Amin7-Jul-04 4:18 
GeneralMemory usage of 1 form Pin
dev1t6-Jul-04 17:25
dev1t6-Jul-04 17:25 
GeneralRe: Memory usage of 1 form Pin
insurgentpyro6-Jul-04 18:57
insurgentpyro6-Jul-04 18:57 
GeneralRe: Memory usage of 1 form Pin
dev1t7-Jul-04 3:01
dev1t7-Jul-04 3:01 
GeneralRe: Memory usage of 1 form Pin
Peter Vertes7-Jul-04 3:48
Peter Vertes7-Jul-04 3:48 
GeneralRe: Memory usage of 1 form Pin
Dave Kreskowiak7-Jul-04 4:53
mveDave Kreskowiak7-Jul-04 4:53 
GeneralRe: Memory usage of 1 form Pin
Heath Stewart7-Jul-04 5:09
protectorHeath Stewart7-Jul-04 5:09 
This is a Runtime application. The Common Language Runtime (CLR) is loaded, along with the base class libraries (BCL assemblies) and any third-party assemblies when the Type they define is needed. This can consume quite a bit of memory. The same is true for Java applications and anything that uses a runtime in this manner (C/C++ has a runtime, too, but since it compiles to native code where .NET and Java compile to bytecode, that runtime is just common functions).

There are things you can do to help eliminate waste, though. For example, when you show a modal form (when you call Form.ShowDialog), make sure you call Dispose on the forum afterware to clean-up native resources. Native resources aren't managed by the Runtime GC (Garbage Collector), so they must be freed by calling Dispose (and there's a lot of discussion about finalizers and Dispose on the 'net you can google for).

A good way to make sure a form is always disposed is using the using block statement:
using (PromptForm form = new PromptForm())
{
  DialogResult result = form.ShowDialog();
  if (result == DialogResult.OK)
    return form.Answer;
  else return null;
}
PromptForm is just a made-up form that asks a question and lets the user type in an answer. If the OK button was clicked (and it's DialogResult property is set to DialogResult.OK), you return the answer; otherwise, you return null (again, just an example). Before the answer or null is returned, the form variable is disposed since the above translates to:
PromptForm form = new PromptForm();
try
{
  // Rest of code goes here
}
finally
{
  form.Dispose();
}
In a try-catch-finally or try-finally, the finally block is always exectued even if an exception is thrown (the only case where it's not is when you call Environment.Exit, which unloads the CLR and only finalizers are called).

There are many other things you can do as well. I suggest you go to MSDN[^] and browse some of the articles about memory management and the CLR.

 

Microsoft MVP, Visual C#
My Articles
QuestionHow to use the function directly Pin
luming11223344556-Jul-04 16:44
luming11223344556-Jul-04 16:44 
AnswerRe: How to use the function directly Pin
insurgentpyro6-Jul-04 18:56
insurgentpyro6-Jul-04 18:56 
AnswerRe: How to use the function directly Pin
Stefan Troschuetz6-Jul-04 20:33
Stefan Troschuetz6-Jul-04 20:33 
GeneralRe: How to use the function directly Pin
luming11223344556-Jul-04 21:46
luming11223344556-Jul-04 21:46 
Generalvga output from PPC using C# Pin
wilk00776-Jul-04 16:19
wilk00776-Jul-04 16:19 
GeneralSearch Command Pin
Anonymous6-Jul-04 15:19
Anonymous6-Jul-04 15:19 
GeneralRe: Search Command Pin
insurgentpyro6-Jul-04 18:54
insurgentpyro6-Jul-04 18:54 
GeneralRe: Search Command Pin
hpAng6-Jul-04 21:30
hpAng6-Jul-04 21:30 
GeneralRe: Search Command Pin
Heath Stewart7-Jul-04 4:26
protectorHeath Stewart7-Jul-04 4:26 
GeneralHttpWebRequest Pin
Moon Boy6-Jul-04 14:23
Moon Boy6-Jul-04 14:23 
GeneralRe: HttpWebRequest Pin
Heath Stewart7-Jul-04 4:19
protectorHeath Stewart7-Jul-04 4:19 
Generalneed sp_helpdb return values Pin
betterc6-Jul-04 14:06
betterc6-Jul-04 14:06 
GeneralRe: need sp_helpdb return values Pin
leppie6-Jul-04 14:55
leppie6-Jul-04 14:55 
GeneralRe: need sp_helpdb return values Pin
betterc6-Jul-04 14:57
betterc6-Jul-04 14:57 
GeneralRe: need sp_helpdb return values Pin
betterc7-Jul-04 1:20
betterc7-Jul-04 1:20 
GeneralRe: need sp_helpdb return values Pin
Heath Stewart7-Jul-04 3:56
protectorHeath Stewart7-Jul-04 3:56 
GeneralRe: need sp_helpdb return values Pin
betterc7-Jul-04 6:19
betterc7-Jul-04 6:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.