-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutoreleaseScope.cs
53 lines (46 loc) · 1.11 KB
/
AutoreleaseScope.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// Copyright (C) 2008 Eugeny Grishul
//
// See license in License.txt
//
using System;
using System.Runtime.InteropServices;
namespace NObjective
{
/// <summary>
/// Provides NSAutoreleasePool functionality with "using" pattern:
/// <code>
/// using( new AutoreleaseScope() ) {
/// ...
/// ...
/// ...
/// }
/// </code>
/// </summary>
public struct AutoreleaseScope : IDisposable
{
/// <summary>
/// Points to NSAutoreleasePool object.
/// </summary>
private RuntimeObject _handle;
/// <summary>
/// Creates new NSAutoreleasePool object.
/// </summary>
public static AutoreleaseScope New()
{
return new AutoreleaseScope {
_handle = new RuntimeObject( Runtime.SendMessage( Runtime.SendMessage( RuntimeClasses.NSAutoreleasePool, Selectors.alloc ), Selectors.init ) )
};
}
#region IDisposable Members
/// <summary>
/// Releases internal NSAutoreleasePool object.
/// </summary>
public void Dispose()
{
Runtime.SendMessage( _handle, Selectors.release );
_handle = RuntimeObject.Null;
}
#endregion
}
}