Atozed Forums

Full Version: HTTP/TCPServer Intercept
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm setting up intercepts like this in my OnConnect events to track total bytes coming in and going out:

Code:
AContext.Connection.Intercept := TIdConnectionIntercept.Create(AContext.Connection);  // track total bytes in and out
AContext.Connection.Intercept.OnReceive := InterceptEvents.OnReceive;
AContext.Connection.Intercept.OnSend := InterceptEvents.OnSend;

Do I need to call AContext.Connection.Intercept.Free in the OnDisconnect event or does that get cleaned up automatically when the connection ends?
(05-05-2022, 05:33 PM)kbriggs Wrote: [ -> ]Do I need to call AContext.Connection.Intercept.Free in the OnDisconnect event

No. The server will free the Intercept after firing the OnDisconnect event (unless the event handler raises an exception). But, even if the server didn't free the Intercept automatically, you are assigning the AContext.Connection as the Owner of the Intercept, so the Intercept would be freed anyway when the Connection is freed.