本文整理汇总了C#中MObjc.NSObject.release方法的典型用法代码示例。如果您正苦于以下问题:C# NSObject.release方法的具体用法?C# NSObject.release怎么用?C# NSObject.release使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MObjc.NSObject
的用法示例。
在下文中一共展示了NSObject.release方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ArrayArg
public void ArrayArg()
{
NSObject pool = new NSObject(NSObject.AllocAndInitInstance("NSAutoreleasePool"));
Class nsData = new Class("NSData");
long bytes = DoGetMemory();
for (int j = 1; j < 100; ++j)
{
for (int i = 0; i < NumIterations/100; ++i)
{
byte[] data = new byte[]{2, 5, 6, 3};
NSObject d = new NSObject(nsData.Call("alloc"));
NSObject e = (NSObject) d.Call("initWithBytes:length:", data, data.Length);
e.release();
}
GC.Collect();
}
pool.release();
GC.Collect();
GC.WaitForPendingFinalizers();
long delta = DoGetMemory() - bytes;
if (delta/NumIterations > 4)
Assert.Fail("ArrayArg used {0}K of memory ({1} bytes per iteration)!", delta/1024, delta/NumIterations);
}
示例2: Main
internal static void Main(string[] args)
{
try
{
Registrar.CanInit = true;
// Make our app a foreground app (this is redundant if we were started via the
// Finder or the open command, but important if we were started by directly
// executing the launcher script).
var psn = new ProcessSerialNumber();
psn.highLongOfPSN = 0;
psn.lowLongOfPSN = kCurrentProcess;
int err = TransformProcessType(ref psn, kProcessTransformToForegroundApplication);
if (err != 0)
throw new InvalidOperationException("TransformProcessType returned " + err + ".");
err = SetFrontProcess(ref psn);
if (err != 0)
throw new InvalidOperationException("SetFrontProcess returned " + err + ".");
// Load the nib and run the main event loop.
NSObject pool = new NSObject(NSObject.AllocAndInitInstance("NSAutoreleasePool"));
App app = new App("MainMenu.nib");
pool.release();
app.Run();
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
示例3: DeallocTest2
public void DeallocTest2()
{
NSObject pool = new NSObject(NSObject.AllocAndInitInstance("NSAutoreleasePool"));
MyDerived instance = (MyDerived) new Class("MyDerived").Call("alloc").Call("init");
Assert.AreEqual(1L, instance.retainCount());
instance.release();
Assert.IsTrue(instance.Dead);
pool.release();
}
示例4: ChainedCallTest
public void ChainedCallTest()
{
NSObject pool = new NSObject(NSObject.AllocAndInitInstance("NSAutoreleasePool"));
Class nsString = new Class("NSMutableString");
NSObject str = (NSObject) nsString.Call("alloc").Call("initWithUTF8String:", Marshal.StringToHGlobalAuto("chained!"));
string result = Marshal.PtrToStringAuto((IntPtr) str.Call("UTF8String"));
Assert.AreEqual("chained!", result);
pool.release();
}
示例5: NilCallTest
public void NilCallTest()
{
NSObject pool = new NSObject(NSObject.AllocAndInitInstance("NSAutoreleasePool"));
NSObject nil = new NSObject(IntPtr.Zero);
// Calling an NSObject method on nil does nothing and returns nil.
NSObject result = (NSObject) nil.Call("hash");
Assert.IsTrue(result.IsNil());
// Calling a unknown method on nil does nothing and returns nil.
result = (NSObject) nil.Call("foo");
Assert.IsTrue(result.IsNil());
// Can chain calls to nil.
result = (NSObject) nil.Call("foo").Call("bar");
Assert.IsTrue(result.IsNil());
// Can use Native with null.
result = (NSObject) nil.Call("foo");
Assert.IsTrue(result.IsNil());
pool.release();
}
示例6: ThreadedTest
public void ThreadedTest()
{
NSObject pool = new NSObject(NSObject.AllocAndInitInstance("NSAutoreleasePool"));
sbyte threaded = (sbyte) new Class("NSThread").Call("isMultiThreaded");
Assert.AreEqual(1, threaded);
pool.release();
}
示例7: SuperTest
public void SuperTest()
{
NSObject pool = new NSObject(NSObject.AllocAndInitInstance("NSAutoreleasePool"));
Media instance = (Media) new Class("Media").Call("alloc").Call("init");
int value = instance.value();
Assert.AreEqual(3, value);
value = instance.Call("value").To<int>();
Assert.AreEqual(3, value);
pool.release();
}
示例8: RefCount3Test
public void RefCount3Test()
{
NSObject pool = new NSObject(NSObject.AllocAndInitInstance("NSAutoreleasePool"));
Class klass = new Class("NSHashTable");
NSObject instance1 = (NSObject) klass.Call("alloc").Call("init");
Assert.AreEqual(1L, instance1.retainCount());
NSObject instance2 = (NSObject) new Class("NSHashTable").Call("alloc").Call("init");
Assert.AreEqual(1L, instance2.retainCount());
pool.release();
Assert.AreEqual(1L, instance1.retainCount());
Assert.AreEqual(1L, instance2.retainCount());
}
示例9: RefCount2Test
public void RefCount2Test()
{
NSObject pool = new NSObject(NSObject.AllocAndInitInstance("NSAutoreleasePool"));
// No copy, new, or alloc so ref count is one and it's owned by the pool.
PrettyData direct = PrettyData.makeDefault();
Assert.AreEqual(1L, direct.retainCount());
// Alloc so pool has no ownership stake.
NSObject indirect = (NSObject) new Class("PrettyData").Call("alloc").Call("init");
Assert.AreEqual(1L, indirect.retainCount());
// If we send a message to an object its retain count doesn't change.
int value = (int) direct.Call("get33");
Assert.AreEqual(33, value);
Assert.AreEqual(1L, direct.retainCount());
pool.release();
// Verify our counts after we empty the release pool.
Assert.IsTrue(direct.IsDeallocated());
Assert.AreEqual(1L, indirect.retainCount());
}
示例10: RefCount1Test
public void RefCount1Test()
{
NSObject pool = new NSObject(NSObject.AllocAndInitInstance("NSAutoreleasePool"));
// If we use alloc the object will have a ref count of one.
NSObject instance = (NSObject) new Class("NSHashTable").Call("alloc").Call("init");
Assert.AreEqual(1L, instance.retainCount());
// Classes always have a very high retain count (because they
// are not supposed to go away).
Class nsSignature = new Class("NSMethodSignature");
Assert.IsTrue(nsSignature.retainCount() > 1000);
// If alloc, new, or copy aren't used then the pool owns the object.
Class nsString = new Class("NSString");
NSObject str = (NSObject) nsString.Call("stringWithUTF8String:", Marshal.StringToHGlobalAuto("hello"));
Assert.AreEqual(1L, str.retainCount());
// We can have two managed instances on the same native instance
// and the ref count doesn't change.
NSObject copy = new NSObject((IntPtr) instance);
Assert.AreEqual(1L, copy.retainCount());
// If we send a message to an object its retain count doesn't change.
instance.Call("description");
Assert.AreEqual(1L, instance.retainCount());
pool.release();
// Verify our counts after we empty the release pool.
Assert.AreEqual(1L, instance.retainCount());
Assert.AreEqual(1L, copy.retainCount());
}
示例11: Formatted
public void Formatted()
{
NSObject pool = new NSObject(NSObject.AllocAndInitInstance("NSAutoreleasePool"));
long bytes = DoGetMemory();
for (int j = 1; j < 100; ++j)
{
for (int i = 0; i < NumIterations/100; ++i)
{
NSObject s = (NSObject) Native.Call("[[NSNumber alloc] initWithInteger:{0}]", 33);
s.release();
}
GC.Collect();
}
pool.release();
GC.Collect();
GC.WaitForPendingFinalizers();
long delta = DoGetMemory() - bytes;
if (delta/NumIterations > 4)
Assert.Fail("Formatted used {0}K of memory ({1} bytes per iteration)!", delta/1024, delta/NumIterations);
}
示例12: Released
public void Released()
{
NSObject pool = new NSObject(NSObject.AllocAndInitInstance("NSAutoreleasePool"));
long bytes = DoGetMemory();
for (int j = 1; j < 100; ++j)
{
for (int i = 0; i < NumIterations/100; ++i)
{
Class klass = new Class("NSNumber");
klass.release();
}
GC.Collect();
}
pool.release();
GC.Collect();
GC.WaitForPendingFinalizers();
long delta = DoGetMemory() - bytes;
if (delta/NumIterations > 4)
Assert.Fail("Released used {0}K of memory ({1} bytes per iteration)!", delta/1024, delta/NumIterations);
}
示例13: Managed
public void Managed()
{
NSObject pool = new NSObject(NSObject.AllocAndInitInstance("NSAutoreleasePool"));
long bytes = DoGetMemory();
for (int j = 1; j < 100; ++j)
{
for (int i = 0; i < NumIterations/100; ++i)
{
NSObject instance = (NSObject) new Class("Subclass1").Call("alloc").Call("init");
instance.Call("TakeString", "what");
instance.release();
}
GC.Collect();
}
pool.release();
GC.Collect();
GC.WaitForPendingFinalizers();
long delta = DoGetMemory() - bytes;
if (delta/NumIterations > 4)
Assert.Fail("Managed used {0}K of memory ({1} bytes per iteration)!", delta/1024, delta/NumIterations);
}
示例14: IntArg
public void IntArg()
{
NSObject pool = new NSObject(NSObject.AllocAndInitInstance("NSAutoreleasePool"));
long bytes = DoGetMemory();
Class nsString = new Class("NSString");
NSObject str = (NSObject) nsString.Call("stringWithUTF8String:", Marshal.StringToHGlobalAuto("hello world"));
for (int j = 1; j < 100; ++j)
{
for (int i = 0; i < NumIterations/100; ++i)
{
str.Call("characterAtIndex:", 2);
}
GC.Collect();
}
pool.release();
GC.Collect();
GC.WaitForPendingFinalizers();
long delta = DoGetMemory() - bytes;
if (delta/NumIterations > 4)
Assert.Fail("IntArg used {0}K of memory ({1} bytes per iteration)!", delta/1024, delta/NumIterations);
}
示例15: Native
public void Native()
{
NSObject pool = new NSObject(NSObject.CreateNative("NSAutoreleasePool"));
Random rng = new Random(1);
NSMutableArray values = NSMutableArray.Create();
for (int i = 0; i < ArraySize; ++i)
values.addObject(NSString.Create(rng.Next().ToString()));
Stopwatch timer = Stopwatch.StartNew();
for (uint i = 0; i < values.count(); ++i)
{
for (uint j = values.count() - 1; j > i; --j)
{
NSString s1 = values.objectAtIndex(j).To<NSString>();
NSString s2 = values.objectAtIndex(j - 1).To<NSString>();
if (s2.compare(s1) > 0)
{
values.replaceObjectAtIndexWithObject(j, s2);
values.replaceObjectAtIndexWithObject(j - 1, s1);
}
}
}
Console.WriteLine("native {0:0.0} secs", timer.ElapsedMilliseconds/1000.0);
for (uint i = 0; i < Math.Min(values.count() - 1, 100); ++i)
{
NSString s1 = values.objectAtIndex(i).To<NSString>();
NSString s2 = values.objectAtIndex(i + 1).To<NSString>();
Assert.IsTrue(s1.compare(s2) <= 0);
}
pool.release();
}