The Dispose Finalize pattern is being used to free the resources in .net. In the C++ world, the resource freeing was deterministic. In .net, it is not. The rule of thumb is to use Dispose to free non-managed resources and Finalize to free managed resources. To use Dispose method, the class has to implement the IDisposable interface. The Dispose method needs to be called explicitly. Normally it is done in using statement. The Finalize is defined like a C++ destructor with ~. The Finalize is expensive and run from different threads by the .net. If Dispose is being called to free a resource, make sure there is a suppress call to Finalize to supress further resource freeing.
Archive for April, 2010
.net Dispose Vs Finalize
Tuesday, April 27th, 2010Threading in .net
Monday, April 26th, 2010There are two ways to create threads in .net. Using the .net threadpool, a thread can be created and run. They are efficient than manually creating a thread and running. It is expensive creating and destroying threads manually. The threadpool manages the thread switching efficiently. The WCF, web services, asp.net web request are all multi threaded apps running in a .net thread pool. The BackgroundWorker helps to create worker thread and run. It is efficient as ThreadPool – Threadpool calls BackgroundWorker to run tasks. This uses events mechanism to queue up functions.
The synchronization can be achieved with Mutex.Start() and Mutex.Stop() critical section objects. The lock() can also be used to protect an area of operation. When locking is used, it is important to lock objects only – locking primitive data items and the lock will create boxes to handle it. Each item a thread is created for a request, boxing happens, and there is no synchronization.
.net memory leakage
Sunday, April 25th, 2010Is a memory leakage possible in .net? Yes. The unmanages resources should be freed by the application through Dispose. The other situation when a leakage can happen is when the events registered with some object and they are not freed through unregister. Third situation a memory leak can happen is when the collections are not freed before adding again as shown below. It is not necessary to call GC.Collect unless there is heavy usage of memory in an app and should be freed. When the GC.Collect is called, the GC goes through the finalizers of all the objects.
For i = 0 To 1000
da.Fill(DS, "Table" + i.ToString)
Next
Viewstate Vs Hidden Field in asp.net
Friday, April 23rd, 2010- Viewstate is 64 bit encrypted. The hidden fields are not.
- Viewstate is available between the client and server on a single page. The hidden fields are transmitted between pages.
- We can save objects in Viewstate. They have to be serializable objects. The hiddle fields handle primitive data types.
- Viewstate is expensive because the data is transferred between the client and server.
sql and dotnet questions
Thursday, April 22nd, 2010- Can we insert a record to the view?
- What is a view?
- Can we insert a record through the trigger?
- How do you handle timeout with transaction?
- Difference between join and union?
- What is union and union all?
- What is inner join and outer join?
- Difference between method overloading and overriding.
- What is Cross Table Extensions
- What is Microsoft Enterprise Library
- What is the difference between Shallow Copy and Deep Copy
- Difference between thread and worker thread
- Method extensions like ToString()
- Difference between IF and AS
- How to work flow three different end points A,B,C or just A,B? SOA?
- Can View state has objects?
- Application Vs Cache
- Performance improvement in the business layer and the database layer?
- Is the order of fields in the where clause make a difference.
- Difference between Stored Proc and User defined functions
- What is the difference between asp.net Label Vs Literal control?
- How many maximum garbage collectors you can have in .net?
- How many app domains you can have in .net?
- What interfaces support forach loop? IDisposable, IEnumerable.
- What is internpool in .net?
- How to invoke a class from a dll programmatic ally in .net?
- Can a managed app call un-managed app or dll?