mac: Fix more memory warnings

This commit is contained in:
Hylke Bons 2012-03-01 20:46:25 +00:00
parent bc749a31f5
commit 84413d2c53
3 changed files with 139 additions and 107 deletions

View file

@ -40,6 +40,8 @@ namespace SparkleShare {
public SparkleAbout (IntPtr handle) : base (handle) { }
public SparkleAbout () : base ()
{
using (var a = new NSAutoreleasePool ())
{
SetFrame (new RectangleF (0, 0, 640, 281), true);
Center ();
@ -53,46 +55,64 @@ namespace SparkleShare {
BackingType = NSBackingStore.Buffered;
CreateAbout ();
}
Controller.HideWindowEvent += delegate {
using (var a = new NSAutoreleasePool ())
{
InvokeOnMainThread (delegate {
PerformClose (this);
});
}
};
Controller.ShowWindowEvent += delegate {
using (var a = new NSAutoreleasePool ())
{
InvokeOnMainThread (delegate {
OrderFrontRegardless ();
});
}
};
Controller.NewVersionEvent += delegate (string new_version) {
using (var a = new NSAutoreleasePool ())
{
InvokeOnMainThread (delegate {
UpdatesTextField.StringValue = "A newer version (" + new_version + ") is available!";
UpdatesTextField.TextColor =
NSColor.FromCalibratedRgba (0.45f, 0.62f, 0.81f, 1.0f);
});
}
};
Controller.VersionUpToDateEvent += delegate {
using (var a = new NSAutoreleasePool ())
{
InvokeOnMainThread (delegate {
UpdatesTextField.StringValue = "You are running the latest version.";
UpdatesTextField.TextColor =
NSColor.FromCalibratedRgba (0.45f, 0.62f, 0.81f, 1.0f);
});
}
};
Controller.CheckingForNewVersionEvent += delegate {
using (var a = new NSAutoreleasePool ())
{
InvokeOnMainThread (delegate {
UpdatesTextField.StringValue = "Checking for updates...";
UpdatesTextField.TextColor =
NSColor.FromCalibratedRgba (0.45f, 0.62f, 0.81f, 1.0f); // Tango Sky Blue #1
});
}
};
}
private void CreateAbout ()
{
using (var a = new NSAutoreleasePool ())
{
string about_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
"Pixmaps", "about.png");
@ -162,6 +182,7 @@ namespace SparkleShare {
ContentView.AddSubview (UpdatesTextField);
ContentView.AddSubview (CreditsTextField);
}
}
public override void OrderFrontRegardless ()

View file

@ -244,11 +244,16 @@ namespace SparkleShare {
this.popup_button.Menu.AddItem (NSMenuItem.SeparatorItem);
this.popup_button.AddItems (folders);
this.popup_button.Activated += delegate {
this.popup_button.Activated += delegate { // FIXME: Still causes some memory leak warnings
using (var b = new NSAutoreleasePool ())
{
InvokeOnMainThread (delegate {
if (this.popup_button.IndexOfSelectedItem == 0)
Controller.SelectedFolder = null;
else
Controller.SelectedFolder = this.popup_button.SelectedItem.Title;
});
}
};
ContentView.AddSubview (this.popup_button);

View file

@ -41,13 +41,13 @@ namespace SparkleShare {
public SparkleUI ()
{
using (var a = new NSAutoreleasePool ())
{
// Use translations
Catalog.Init ("sparkleshare",
Path.Combine (NSBundle.MainBundle.ResourcePath, "Translations"));
using (NSAutoreleasePool pool = new NSAutoreleasePool ()) {
// Needed for Growl
GrowlApplicationBridge.WeakDelegate = this;
GrowlApplicationBridge.Delegate = new SparkleGrowlDelegate ();
@ -76,6 +76,8 @@ namespace SparkleShare {
public void SetFolderIcon ()
{
using (var a = new NSAutoreleasePool ())
{
string folder_icon_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
"sparkleshare-mac.icns");
@ -85,6 +87,7 @@ namespace SparkleShare {
NSWorkspace.SharedWorkspace.SetIconforFile (folder_icon,
Program.Controller.SparklePath, 0);
}
}
public void Run ()
@ -113,9 +116,12 @@ namespace SparkleShare {
private void ShowDockIcon ()
{
using (var a = new NSAutoreleasePool ())
{
NSApplication.SharedApplication.ActivationPolicy = NSApplicationActivationPolicy.Regular;
}
}
[Export("registrationDictionaryForGrowl")]