Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

c# coding

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
viji - 03 Mar 2008 14:46 GMT
How to allocate and de-allocate the memory thr' C# with example coding?
Bob Powell [MVP] - 03 Mar 2008 14:13 GMT
//allocate
thing X=new thing();

//deallocate
x.Dispose(); //(optional if object implements dispose pattern)
x=null;

In managed code, memory is deallocated by the garbage collector when it's no
longer needed.

Signature

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

> How to allocate and de-allocate the memory thr' C# with example coding?
Richard Blewett - 04 Mar 2008 11:20 GMT
> //allocate
> thing X=new thing();
[quoted text clipped - 5 lines]
> In managed code, memory is deallocated by the garbage collector when it's
> no longer needed.

If the OP really wants to talk about *memory* then the call to Dispose does
nothing about memory but does allow the object to clear up non-memory
resources.

The setting of x to null is unnecessary and doesn;t do anything at all as x
is a local variable. If x was static then setting to null would be vital in
allowing the object to be cleaned up. If x were a member variable then
setting it to null *might* be worth it

Signature

Regards

Richard Blewett
DevelopMentor
http://www.dotnetconsult.co.uk/weblog2

Jon - 06 Mar 2008 11:49 GMT
"but does allow the object to clear up non-memory resources"
Which may themselves use memory.

> //allocate
> thing X=new thing();
[quoted text clipped - 5 lines]
> In managed code, memory is deallocated by the garbage collector when it's
> no longer needed.

If the OP really wants to talk about *memory* then the call to Dispose does
nothing about memory but does allow the object to clear up non-memory
resources.

The setting of x to null is unnecessary and doesn;t do anything at all as x
is a local variable. If x was static then setting to null would be vital in
allowing the object to be cleaned up. If x were a member variable then
setting it to null *might* be worth it

Signature

Regards

Richard Blewett
DevelopMentor
http://www.dotnetconsult.co.uk/weblog2

Bob Powell [MVP] - 06 Mar 2008 22:08 GMT
>> thing X=new thing();
x
is a local variable.

Do you see a class declaration in there??

Signature

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

>> //allocate
>> thing X=new thing();
[quoted text clipped - 14 lines]
> in allowing the object to be cleaned up. If x were a member variable then
> setting it to null *might* be worth it
Jon Skeet [C# MVP] - 06 Mar 2008 23:20 GMT
> >> thing X=new thing();
> x
> is a local variable.
>
> Do you see a class declaration in there??

No, but then I didn't see a method declaration either.

If X is really meant to be a local variable, then setting it to null is
almost certainly  a bad idea - and if Thing implements IDisposable,
then a using statement would almost certainly be more appropriate than
manually calling Dispose.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

clintonG - 03 Mar 2008 15:10 GMT
We don't need to alloc anymore which is why develolping ASP.NET is called
Managed Code. As for examples you should spend some time learning what
ASP.NET actually is and how the compiler works.

//try this to get started using the overview keyword
//Microsoft uses this keyword for --everything-- we want
//to learn about

//search
asp.net overview site:msdn2.microsoft.com

//search
managed code overview site:msdn2.microsoft.com

> How to allocate and de-allocate the memory thr' C# with example coding?
Robert Fuchs - 03 Mar 2008 17:55 GMT
why are you talking about ASP.NET?
Nobody asked for that.
The OP asked about C#...

regards, Robert

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.