Commit b72ef4e9 by Stefan Schreistetter

Fixed memory leak.

parent 241680ff
...@@ -13,10 +13,10 @@ namespace TrackerBridge.DSP ...@@ -13,10 +13,10 @@ namespace TrackerBridge.DSP
private GazeData output; private GazeData output;
private Single outputFrequency; private Single outputFrequency;
private Timer timer;
private readonly Object outputLock = new Object(); private readonly Object outputLock = new Object();
private readonly Object valueCountLock = new Object(); private readonly Object valueCountLock = new Object();
private Int64 valueCount; private Int64 valueCount;
private Task timerTask;
private Int64 ValueCount { private Int64 ValueCount {
get { get {
...@@ -51,7 +51,7 @@ namespace TrackerBridge.DSP ...@@ -51,7 +51,7 @@ namespace TrackerBridge.DSP
public GazeDecimator(GazeDataProcessor dataProcessor) public GazeDecimator(GazeDataProcessor dataProcessor)
{ {
outputFrequency = dataProcessor.OutputFrequency; outputFrequency = dataProcessor.OutputFrequency;
Task timerTask = Task.Run(() => TriggerOutput(outputFrequency)); SetupTimer();
} }
public void Input(GazeData input, Object sender = null) public void Input(GazeData input, Object sender = null)
{ {
...@@ -76,9 +76,11 @@ namespace TrackerBridge.DSP ...@@ -76,9 +76,11 @@ namespace TrackerBridge.DSP
ValueCount = 0; ValueCount = 0;
} }
private void TriggerOutput(Single frequency) private void SetupTimer()
{ {
Timer timer = new Timer(1000.0 / frequency); //TODO: Implement Dispose timer?.Stop();
timer?.Dispose();
timer = new Timer(1000.0 / outputFrequency);
timer.Elapsed += (Object sender, ElapsedEventArgs e) => timer.Elapsed += (Object sender, ElapsedEventArgs e) =>
{ {
if (ValueCount > 0) if (ValueCount > 0)
...@@ -94,9 +96,7 @@ namespace TrackerBridge.DSP ...@@ -94,9 +96,7 @@ namespace TrackerBridge.DSP
public void Update(GazeDataProcessor dataProcessor) public void Update(GazeDataProcessor dataProcessor)
{ {
outputFrequency = dataProcessor.OutputFrequency; outputFrequency = dataProcessor.OutputFrequency;
//timerTask.Dispose(); //TODO: Implement proper cancellation SetupTimer();
//TODO: Fix memory leak
timerTask = Task.Run(() => TriggerOutput(outputFrequency));
} }
} }
} }
...@@ -20,7 +20,7 @@ namespace TrackerBridge ...@@ -20,7 +20,7 @@ namespace TrackerBridge
} }
private readonly GazeDataProcessor gazeDataProcessor; private readonly GazeDataProcessor gazeDataProcessor;
private Task timerTask; private System.Timers.Timer timer;
private Single trackerFrequency; private Single trackerFrequency;
public Single OutputFrequency { public Single OutputFrequency {
...@@ -33,9 +33,8 @@ namespace TrackerBridge ...@@ -33,9 +33,8 @@ namespace TrackerBridge
return trackerFrequency; return trackerFrequency;
} }
set { set {
//timerTask.Dispose(); //TODO: Proper cancellation trackerFrequency = value;
//TODO: Fix memory leak TimerSetup();
timerTask = Task.Run(() => SimulateGazeDataHz(value));
} }
} }
...@@ -47,12 +46,15 @@ namespace TrackerBridge ...@@ -47,12 +46,15 @@ namespace TrackerBridge
public void Connect() public void Connect()
{ {
timerTask = Task.Run(() => SimulateGazeDataHz(trackerFrequency)); TimerSetup();
ConnectionEvent?.Invoke(this); ConnectionEvent?.Invoke(this);
} }
private void SimulateGazeDataHz(Single frequency)
private void TimerSetup()
{ {
System.Timers.Timer timer = new System.Timers.Timer(1000.0 / frequency); //TODO: Implement Dispose timer?.Stop();
timer?.Dispose();
timer = new System.Timers.Timer(1000.0 / trackerFrequency);
timer.Elapsed += (Object sender, ElapsedEventArgs e) => timer.Elapsed += (Object sender, ElapsedEventArgs e) =>
{ {
Point mousePosition = Control.MousePosition; Point mousePosition = Control.MousePosition;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment