1 Idisposable BP Csharp Developers Slides
1 Idisposable BP Csharp Developers Slides
for C# Developers
Introducing IDisposable
Elton Stoneman
geekswithblogs.net/eltonstoneman
@EltonStoneman
Introducing IDisposable
Stack
Introducing IDisposable
Stack
{...} int32
Introducing IDisposable
Releases memory
Introducing IDisposable
Releases memory
Introducing IDisposable
Releases memory
Not Using IDisposable?
6
Expanding memory
w
Hogging external
b
Functional defects
profile resources
Introducing IDisposable
Summary
namespace System
{
public interface IDisposable
{
void Dispose();
}
}
IDisposable
provides a mechanism for
releasing unmanaged
resources
Unmanaged Resources
Runtime-callable wrapper
Managed code External COM library
Managed access
Managed code External resources
/* ... */
}
/* ... */
Managed Code
Demo 2: The Word Counting App
b
Summary
Introducing IDisposable
Interface definition
Meaning
Unmanaged resources
Native code– IntPtr & interop
*And* managed code
Which implements IDisposable What Happens
May or may not use unmanaged resources when the GC
Runs?
Demo solution
File IO, SQL and WCF