Revision: 380
http://qttabbar.svn.sourceforge.net/qttabbar/?rev=380&view=rev
Author: masamunexgp
Date: 2012-01-12 23:54:40 +0000 (Thu, 12 Jan 2012)
Log Message:
-----------
Fix major memory leak.
Modified Paths:
--------------
branches/options/QTTabBar/OptionsDialog/OptionsDialog.xaml.cs
Modified: branches/options/QTTabBar/OptionsDialog/OptionsDialog.xaml.cs
===================================================================
--- branches/options/QTTabBar/OptionsDialog/OptionsDialog.xaml.cs 2012-01-12 06:31:38 UTC (rev 379)
+++ branches/options/QTTabBar/OptionsDialog/OptionsDialog.xaml.cs 2012-01-12 23:54:40 UTC (rev 380)
@@ -30,6 +30,7 @@
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
+using System.Windows.Threading;
using QTTabBarLib.Interop;
using Font = System.Drawing.Font;
using Bitmap = System.Drawing.Bitmap;
@@ -39,7 +40,7 @@
/// <summary>
/// Interaction logic for OptionsDialog.xaml
/// </summary>
- internal partial class OptionsDialog : IDisposable {
+ internal partial class OptionsDialog : Window {
private static OptionsDialog instance;
private static Thread instanceThread;
private static Thread launchingThread;
@@ -56,11 +57,11 @@
launchingThread = Thread.CurrentThread;
if(instance == null) {
- instanceThread = new Thread(ThreadEntry);
+ instanceThread = new Thread(ThreadEntry) { IsBackground = true };
instanceThread.SetApartmentState(ApartmentState.STA);
lock(instanceThread) {
instanceThread.Start();
- // Don't return until we know that instance is set.
+ // Don't return until we know that the instance is created!
Monitor.Wait(instanceThread);
}
}
@@ -90,15 +91,18 @@
}
private static void ThreadEntry() {
- using(instance = new OptionsDialog()) {
- lock(instanceThread) {
- Monitor.Pulse(instanceThread);
+ instance = new OptionsDialog();
+ lock(instanceThread) {
+ Monitor.Pulse(instanceThread);
+ }
+ instance.Closed += (sender, e) => {
+ lock(typeof(OptionsDialog)) {
+ instance.Dispatcher.InvokeShutdown();
+ instance = null;
}
- instance.ShowDialog();
- }
- lock(typeof(OptionsDialog)) {
- instance = null;
- }
+ };
+ instance.Show();
+ Dispatcher.Run();
}
#endregion
@@ -133,10 +137,6 @@
}
}
- public void Dispose() {
- // TODO
- }
-
private void UpdateOptions() {
// A small caveat in my brilliant plan to separate the options tabs into separate files:
// The plugin tab has to be committed first, before the others.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|