Following Question in C#

S

Silent Ocean

Hi All

I have following questions regarding C# Assembly and Threading.

Let me know the precise answer or lead me to the proper materials.

1. Is memory leakeage possible in .Net Manager Code ?
2. Is memory leakage possible in .Net Unmanaged Code ?
3. How can I find the what % of memory is being used by DLL at run time ?
4. What is difference between Sunchronous processing and Async
processing in .Net ? How can I achieve it ?
5. Can any one lead me towards Multithreading GUI development in Winforms ?
6. Difference between Delegate and Event ?
7. Is there any specific Design Patterns specifically for WinForms ?

Awaiting reply

Thanks

Silent Ocean
 
G

Guest

Wow that is a lot of questions, with a lot of possible answers:

1. In the pure sense of the words "memory leak" there should be no way for a
managed application to leak memory. Every object or data type you create is
tracked by the .Net environment (CLR) and will be destroyed and reclaimed at
an unspecified time, this is the job of the Garbage collector. It will
periodically go through the memory map looking for objects that are no longer
in scope or referenced in the code, therefore they cannot be accessed, and
can be destroyed, this is not determinitic to the application, it is when the
GC decides it needs to try to reclaim resources it will run (you could force
it using GC.Collect(), but I would not recommend that, the garbage collector
probably knows best when it wants to run).

It is entirely possible that you write code that uses resources such as
memory / file handles / db connections etc and you do not release them
properly, i.e. you somehow keep a reference to the object, so for the
lifetime of your application you will consuming more and more resources which
will look like a kind of memory leak and you keep creating more and more
instances of the object. Look into the IDispose interface and pattern it is
pretty interesting.

2. YES - unmanaged code is not governed by the CLR, you may allocate memory
and not deallocate it therefore causing a memory leak (using languages such
as C, C++), as you are outside of managed code the CLR will have no knowledge
of this and it will not be garbage collected.

3. ???

4. In general Syncronous processing means that the caller of a method will
wait until the method which has been called has completed executing before
the caller continues executing, so for example:

Function A()
{
//Time=0 : Function A is called

//Time=1 : Call Function B, A will not continue beyond this point
//until FunctionB has completed
FunctionB();

//Time=2minutes : FunctionA now reaches this point after waiting on
FunctionB
//to complete
}


Function B()
{
//some really long processing time i.e. 2 minutes
}


An asyncronous call will call a method but the caller will not wait until
the called method returns, it will continue immediately. One example of this
is the BeginRead method of FileStream, you can request to read a section of
data, but you do not have to be blocked waiting for the read to complete,
you can continue processing other things and eventually EndRead will be
called to alert you that the read has completed.

The general pattern is that sometimes a syncronous method will have
asyncronous counterparts called BeginXXX and EndXXX, i.e. BeginInvoke,
EndInvoke, BeginRead, EndRead

5. 6. 7. Jon Skeet has some really excellent articles on this, try:
http://www.yoda.arachsys.com/csharp/threads/winforms.shtml


Hope that helps
Mark.
 
M

Michael S

Silent Ocean said:
Hi All

I have following questions regarding C# Assembly and Threading.

Let me know the precise answer or lead me to the proper materials.

1. Is memory leakeage possible in .Net Manager Code ?

No. That would imply that the GC was buggy.

But under certain circumstances it is possible to have .NET chew all you
memory and die.

The most obvious case is if you have references in a (perhaps) static list
or hastable and forget to remove them when your done with those objects.
Hence these objects will allways be acessable by the GC and never die. This
might seem far fetched, but I have actually managed to do this twice. My
Bad. =)

If you forget to dispose of objects that should be. Streams, sockets and
database objects typically uses a lot of external unmanaged resources and if
they aren't disposed of properly; .NET will hog a lot of memory and your app
will function poorly.
2. Is memory leakage possible in .Net Unmanaged Code ?

Oh Yes. Just allocate away! =)
3. How can I find the what % of memory is being used by DLL at run time ?

Hmm. A DLL doesn't allocate memory. A process can load a DLL (an assembly)
and it's the process that allocates memory. Your question is invalid.
4. What is difference between Sunchronous processing and Async processing
in .Net ? How can I achieve it ?

Also called blocking and unblocking. Blocking code is what you usually get
when calling methods in one thread. With multithreading and callbacks you
achieve asyncronous calls. .NET has excellent support for this.
5. Can any one lead me towards Multithreading GUI development in Winforms
?

I really can't. But there are plenty of topics and books available.
6. Difference between Delegate and Event ?

A delegate is .NET construct and a reference to a method. An Event is
syntactic sugar for coupling and accessing delegates in C#.
7. Is there any specific Design Patterns specifically for WinForms ?

Not really design patterns. But there are best practices. Take a look at the
Exam books from Microsoft for certificates in .NET. They'll teach you how
it's done.
Awaiting reply
Thanks
Silent Ocean

Happy Coding
- Michael S
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top