Commit b72ef4e9 by Stefan Schreistetter

Fixed memory leak.

parent 241680ff
......@@ -13,10 +13,10 @@ namespace TrackerBridge.DSP
private GazeData output;
private Single outputFrequency;
private Timer timer;
private readonly Object outputLock = new Object();
private readonly Object valueCountLock = new Object();
private Int64 valueCount;
private Task timerTask;
private Int64 ValueCount {
get {
......@@ -51,7 +51,7 @@ namespace TrackerBridge.DSP
public GazeDecimator(GazeDataProcessor dataProcessor)
{
outputFrequency = dataProcessor.OutputFrequency;
Task timerTask = Task.Run(() => TriggerOutput(outputFrequency));
SetupTimer();
}
public void Input(GazeData input, Object sender = null)
{
......@@ -76,9 +76,11 @@ namespace TrackerBridge.DSP
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) =>
{
if (ValueCount > 0)
......@@ -94,9 +96,7 @@ namespace TrackerBridge.DSP
public void Update(GazeDataProcessor dataProcessor)
{
outputFrequency = dataProcessor.OutputFrequency;
//timerTask.Dispose(); //TODO: Implement proper cancellation
//TODO: Fix memory leak
timerTask = Task.Run(() => TriggerOutput(outputFrequency));
SetupTimer();
}
}
}
......@@ -20,7 +20,7 @@ namespace TrackerBridge
}
private readonly GazeDataProcessor gazeDataProcessor;
private Task timerTask;
private System.Timers.Timer timer;
private Single trackerFrequency;
public Single OutputFrequency {
......@@ -33,9 +33,8 @@ namespace TrackerBridge
return trackerFrequency;
}
set {
//timerTask.Dispose(); //TODO: Proper cancellation
//TODO: Fix memory leak
timerTask = Task.Run(() => SimulateGazeDataHz(value));
trackerFrequency = value;
TimerSetup();
}
}
......@@ -47,12 +46,15 @@ namespace TrackerBridge
public void Connect()
{
timerTask = Task.Run(() => SimulateGazeDataHz(trackerFrequency));
TimerSetup();
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) =>
{
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