1: public class CompoundObject : IDisposable
2: {
3: //this array takes lot of memory
4: int[] array;
5: //instance of inner finalizable object
6: ClipBoardWrapper cwrapper;
7:
8: public CompoundObject(int hwnd, int elements)
9: {
10: array = new int[elements];
11: cwrapper = new ClipBoardWrapper(hwnd);
12: }
13:
14: public void Dispose()
15: {
16: cwrapper.Dispose();
17: }
18:
19: private class ClipBoardWrapper : IDisposable
20: {
21: [System.Runtime.InteropServices.DllImport("user32")]
22: private static extern int OpenClipboard(int hwnd);
23:
24: [System.Runtime.InteropServices.DllImport("user32")]
25: private static extern int CloseClipboard();
26:
27: public ClipBoardWrapper(int hwnd)
28: {
29: OpenClipboard(hwnd);
30: }
31:
32: public void Dispose()
33: {
34: CloseClipboard();
35: GC.SuppressFinalize(this);
36: }
37: ~ClipBoardWrapper()
38: {
39: Dispose();
40: }
41:
42: }
43: }