[Mono-osx] Memory Leak ?
Matthew Hazlett
hazlema at gmail.com
Sun Jan 9 17:36:16 EST 2011
When I try this:
t = NSTimer.CreateRepeatingScheduledTimer(1,delegate {
txtClock.StringValue = DateTime.Now.ToLongTimeString();
});
I get this error:
Unhandled Exception: System.NullReferenceException: Object reference
not set to an instance of an object
at UglyClock.MainWindowController.<AwakeFromNib>m__0 () [0x00000]
in <filename unknown>:0
at MonoMac.Foundation.NSActionDispatcher.Apply () [0x00000] in
<filename unknown>:0
at (wrapper native-to-managed)
object:[MonoMac.Foundation.NSActionDispatcher:Void Apply()]
(MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector)
at (wrapper managed-to-native)
MonoMac.AppKit.NSApplication:NSApplicationMain (int,string[])
at MonoMac.AppKit.NSApplication.Main (System.String[] args)
[0x00000] in <filename unknown>:0
at UglyClock.MainClass.Main (System.String[] args) [0x00000] in
<filename unknown>:0
My code was working, so I know the objects are all wired correctly.
Humm, seems it can't find txtClock to update this way. If I change the
code to this it works great (So, I know the delegate is working):
t = NSTimer.CreateRepeatingScheduledTimer(1,delegate {
Console.WriteLine(DateTime.Now.ToLongTimeString());
//txtClock.StringValue = DateTime.Now.ToLongTimeString();
});
You know what could be wrong, sorry I'm a total noob, this is my 3rd day
trying to use this.
> hazlema <mailto:hazlema at gmail.com>
> January 9, 2011 4:51 PM
>
>
> Ahh, ok. Thanks
> ------------------------------------------------------------------------
>
> kjpou <mailto:kjpou at pt.lu>
> January 9, 2011 3:33 PM
>
>
> Mathew
>
> It is not a memory leak.
>
> What you have to do is use a NSTimer.
>
> NSTimer t;
>
> t = NSTimer.CreateRepeatingScheduledTimer(1,delegate {
> txtClock.StringValue = DateTime.Now.ToLongTimeString();
> });
>
>
> When you use a .net timer it runs outside NSApplication loop. The
> NSTimer will run within the application loop allowing Cocoa to update
> the field value correctly.
>
> I plan on writing an article about that in a couple of days.
>
>
> ------------------------------------------------------------------------
>
> Matthew Hazlett <mailto:hazlema at gmail.com>
> January 9, 2011 1:52 PM
>
>
>
> I made a terribly simple application, on the MainWindow I put a label
> then in the code I had it update the label every 1000 of a second.
>
> ...
> Timer t = new Timer(1000);
> ...
>
> public override void AwakeFromNib ()
> {
> base.AwakeFromNib ();
>
> t.Elapsed += delegate {
> txtClock.StringValue = DateTime.Now.ToLongTimeString();
> };
>
> t.Start();
> }
>
> But it keeps throwing warning errors at me for every tick, what am I
> missing and how do I fix it?
> /2011-01-09 13:47:30.563 UglyClock[79395:7103] ***
> __NSAutoreleaseNoPool(): Object 0x540f80 of class NSCFString
> autoreleased with no pool in place - just leaking/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-osx/attachments/20110109/c5bc8238/attachment-0001.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: postbox-contact.jpg
Type: image/jpeg
Size: 1525 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-osx/attachments/20110109/c5bc8238/attachment-0002.jpg
-------------- next part --------------
A non-text attachment was scrubbed...
Name: compose-unknown-contact.jpg
Type: image/jpeg
Size: 1421 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-osx/attachments/20110109/c5bc8238/attachment-0003.jpg
More information about the Mono-osx
mailing list