Dekryptor / aforge

Automatically exported from code.google.com/p/aforge
Other
0 stars 0 forks source link

Don't dispose frames after NewFrame event #130

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Currently, the Bitmap provided by the NewFrame event is disposed by
MJPEGStream after it calls the event, making it unusable outside the event
handler unless you clone it.

Original issue reported on code.google.com by chpatr...@gmail.com on 1 Mar 2010 at 11:16

GoogleCodeExporter commented 8 years ago
Yes, we know. It is documented and it was intended design.

Original comment by andrew.k...@gmail.com on 2 Mar 2010 at 8:01

GoogleCodeExporter commented 8 years ago
Couldn't you add a bool to NewFrameEventArgs that controls whether the frame is
disposed after the event handler, set to true by default?

Original comment by chpatr...@gmail.com on 4 Mar 2010 at 11:23

GoogleCodeExporter commented 8 years ago
You simply don't think about global picture ...

As you know, we may have 2 or more clients listening for event. So when event 
is 
fired all their event handlers are invoked. In this case who will be 
responsible for 
disposing? With bool it does not get better, but maybe even worse. One will set 
bool 
to true (dispose), another will set to false (not dispose), but it will crash 
anyway. If both set bool to false (like the case without bool), then who will 
dispose? If one disposes, then another will crash because he still uses it. If 
nobody, then garbage in memory.

Original comment by andrew.k...@gmail.com on 5 Mar 2010 at 8:04

GoogleCodeExporter commented 8 years ago
I see. Thanks anyway.

Original comment by chpatr...@gmail.com on 5 Mar 2010 at 9:37

GoogleCodeExporter commented 8 years ago
Actually, I'm sorry to bother you, but how about this?

in NewFrameEventArgs:

...
private bool disposeFrame = true;
public bool DisposeFrame
{
    get
    {
        return disposeFrame;
    }
}

public void RequestKeepFrame()
{
    lock (disposeFrame) {disposeFrame = false};
}
...

This way handlers that want to keep the frame for later can call 
e.RequestKeepFrame()
and ones who don't won't have to worry about it.

Original comment by chpatr...@gmail.com on 5 Mar 2010 at 8:45

GoogleCodeExporter commented 8 years ago
But what is the difference with the suggestion before? Suppose this scenario. 
Two 
clients call RequestKeepFrame(), so video source does not dispose frame. Who 
will 
dispose the frame then and at what point of time? If nobody, then it means 
garbage 
will grow quickly. If first client will dispose it, then second may crash if it 
did 
not complete its work yet.

Original comment by andrew.k...@gmail.com on 7 Mar 2010 at 10:55