.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Interview Question >> C# >> Post New Question Subscribe to Interview Questions

In .NET Compact Framework, can I free memory explicitly without waiting for garbage collector to free the memory?

Posted By :Shashi Ray     Posted Date :July 15, 2009    Points :10   Category :C# 
Yes you can clear the memory using gc.collect method but it is recommended that u should not call this becouse we don't know the exact time when the gc will be called automatic.

You can also find related Interview Question to In .NET Compact Framework, can I free memory explicitly without waiting for garbage collector to free the memory?  below: 

How Garbage Collector (GC) Works?

The methods in this class influence when an object is garbage collected and when resources allocated by an object are released. Properties in this class provide information about the total amount of memory available in the system and the age category, or generation, of memory allocated to an object. Periodically, the garbage collector performs garbage collection to reclaim memory allocated to objects for which there are no valid references.

Garbage collection happens automatically when a request for memory cannot be satisfied using available free memory. Alternatively, an application can force garbage collection using the Collect method.
Garbage collection consists of the following steps:

The garbage collector searches for managed objects that are referenced in managed code.

The garbage collector attempts to finalize objects that are not referenced.

The garbage collector frees objects that are not referenced and reclaims their memory. (More...)

Can we force garbage collector to run?

System.GC.Collect() forces garbage collector to run. This is not recommended but can be used if situations arise. (More...)

What is Automatic Memory Management in ASP.NET?

Automatic Memory Management: From a programmer's perspective, this is probably the single biggest benefit of the .NET Framework. No, I'm not kidding. Every project I've worked on in my long career of DOS and Windows development has suffered at some point from memory management issues. Proper memory management is hard. Even very good programmers have difficulty with it. It's entirely too easy for a small mistake to cause a program to chew up memory and crash, sometimes bringing the operating system to a screeching halt in the process.

Programmers understand that they're responsible for releasing any memory that they allocate, but they're not very good at actually doing it. In addition, functions that allocate memory as a side effect abound in the Windows API and in the C runtime library. It's nearly impossible for a programmer to know all of the rules. Even when the programmer follows the rules, a small memory leak in a support library can cause big problems if called enough.

The .NET Framework solves the memory management problems by implementing a garbage collector that can keep track of allocated memory references and release the memory when it is no longer referenced. A large part of what makes this possible is the blazing speed of today's processors. When you're running a 2 GHz machine, it's easy to spare a few cycles for memory management. Not that the garbage collector takes a huge number of cycles--it's incredibly efficient.
The garbage collector isn't perfect and it doesn't solve the problem of mis-managing other scarce resources (file handles, for example), but it relieves programmers from having to worry about a huge source of bugs that trips almost everybody up in other programming environments.
On balance, automatic memory management is a huge win in almost every situation. (More...)

Which typically consumes more memory: application state or session state?

Session state tends to use much more memory than application state, because copies of all variables are stored for each user. (More...)

Which typically consumes more memory: application state or session state?

Session state tends to use much more memory than application state, because copies of all variables are stored for each user. (More...)

Name of the command to view the current amount of free (unallocated) space in the database in SQL Server?

Name of command is :sp_spaceused

This command displays the database_size in MB, and it's also shows unallocated space for the database. (More...)

what is session ,cache, cookie, application memory timeout?


Session timeout: 20 min
Cache timeout: duration we have to specify.
Cookie: for in memory cookie till browser opened
For persistent cookie timeout is till expires property's time .
Application memory timeout: till appdomain exist (More...)

How can U Call garbage Collector method()?



please follow this link for full lenghth details:

http://www.developer.com/net/csharp/article.php/3343191/C-Tip-Forcing-Garbage-Collection-in-NET.htm (More...)

How can I find out what the garbage collector is doing?

Lots of interesting statistics are exported from the .NET runtime via the '.NET CLR xxx' performance counters. Use Performance Monitor to view them. (More...)

What happens in memory when you Box and Unbox a value-type?

Boxing converts a value-type to a reference-type, thus storing the object on the heap. Unboxing converts a reference-type to a value-type, thus storing the value on the stack. (More...)

You have got 1 million parking slots. At a time a parking slot can be free or not. To get next slot easily which data structure to implement?

Use Stack.

If you use Stack, we can just get the next slot by using stack.Pop()

If you use List, we have to iterate through all list and check the status and retrieve.

So stack would be advantageous. (More...)

Quick Links For Interview Questions Categories:
ASP.Net Windows Application   .NET Framework   C#   VB.Net   ADO.Net  
Sql Server   SharePoint   Silverlight   OOPs   JQuery   JavaScript/VBScript
Biztalk Patten/Practices .IIS WCF WPF WWF
Networking Aptitude Others   All      

Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.

Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.

So, Start looking our Interview Question section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend