iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (35)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

July 3, 2008
Poll: Which Web editor do you use?
About
 
July 3, 2008
Book Review: Head First JavaScript
WebReference.com
 
July 3, 2008
10 Things You Can Do With a Wiki
About
 
July 2, 2008
Web Host Reviews - 10 New Reviews
About
 
July 2, 2008
14 Reasons You Should Join a Social Network
About
 
July 1, 2008
Mark Boulton's Freelance Design Secrets
SitePoint
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /C#

Managing memory through C# 

  Views:    9003
  Votes:    2
by Pawan Bangar 10/09/04 Rating: 

Synopsis:

C# provides automatic memory management so that developers are freed from manual allocation and de-allocation of blocks of memory.
Pages: firstback1 forwardlast
The Article

public void Push(object o)
{
public void Push (object o)
 {
first = new Node(o, first);
}


class Node
{
public Node Next;
public object Value;
public Node(object value) ; this (value, null) {}
public Node(object value, Node net)  {
Next=nest;
Value=value;
}
}
}
 

The above program shows a Stack class implemented as a linked of Node instances. Node instances are created in the push Method and are garbage collected when no longer needed. A Node instance becomes ineligible for garbage collection when it is no longer possible for any code to access it. When an item is removed from the stack, the associated node instance becomes ineligible for garbage collection.

Following Program shows a test program that uses the stack class:

Class Test {
Static void Main() {
Stack s = new Stack ();
For (int i=0;i<10;i++)
s.Push(i);
while (!s.Empty)
console.WriteLine(s.Pop());
}
}
 

A Stack is created and initialized with 10 elements, and then assigned the value null. Once the variable's' is assigned null, the Stack and the associated 10 Node instances become eligible for garbage collection. The Garbage collector is permitted to clean up immediately, but is not required to do so.

Pages: firstback1 forwardlast



 
  Sponsors