diff --git a/transport/internet/kcp/connection.go b/transport/internet/kcp/connection.go index 7896fdc77..577a88bcc 100644 --- a/transport/internet/kcp/connection.go +++ b/transport/internet/kcp/connection.go @@ -467,6 +467,8 @@ func (this *Connection) Terminate() { this.dataInputCond.Broadcast() this.dataOutputCond.Broadcast() this.writer.Close() + this.sendingWorker.Release() + this.receivingWorker.Release() } func (this *Connection) HandleOption(opt SegmentOption) { diff --git a/transport/internet/kcp/receiving.go b/transport/internet/kcp/receiving.go index 3ff3b1285..28d7aad62 100644 --- a/transport/internet/kcp/receiving.go +++ b/transport/internet/kcp/receiving.go @@ -137,6 +137,10 @@ func NewReceivingWorker(kcp *Connection) *ReceivingWorker { return worker } +func (this *ReceivingWorker) Release() { + this.leftOver.Release() +} + func (this *ReceivingWorker) ProcessSendingNext(number uint32) { this.Lock() defer this.Unlock() diff --git a/transport/internet/kcp/sending.go b/transport/internet/kcp/sending.go index 869d315e9..23f3aa495 100644 --- a/transport/internet/kcp/sending.go +++ b/transport/internet/kcp/sending.go @@ -36,6 +36,15 @@ func NewSendingWindow(size uint32, writer SegmentWriter, onPacketLoss func(uint3 return window } +func (this *SendingWindow) Release() { + if this == nil { + return + } + for _, seg := range this.data { + seg.Release() + } +} + func (this *SendingWindow) Len() int { return int(this.len) } @@ -192,6 +201,10 @@ func NewSendingWorker(kcp *Connection) *SendingWorker { return worker } +func (this *SendingWorker) Release() { + this.window.Release() +} + func (this *SendingWorker) ProcessReceivingNext(nextNumber uint32) { this.Lock() defer this.Unlock()