Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

writeList[0:0]会造成内存泄漏吗 #98

Closed
crossci opened this issue Apr 28, 2021 · 4 comments
Closed

writeList[0:0]会造成内存泄漏吗 #98

crossci opened this issue Apr 28, 2021 · 4 comments

Comments

@crossci
Copy link

crossci commented Apr 28, 2021

func (self *tcpSession) sendLoop() {
	var writeList []interface{}
	for {
		writeList = writeList[0:0]
		exit := self.sendQueue.Pick(&writeList)

如果writeList 里面的量很大 这样会导致一部分内地一直没有释放吗?

@crossci
Copy link
Author

crossci commented Apr 28, 2021

heap profile: 82: 9868976 [40409: 40811376] @ heap/1048576
1: 3719168 [1: 3719168] @ 0x8509e8 0x8516bc 0x460391
#	0x8509e7	github.com/davyxu/cellnet.(*Pipe).Pick+0x1a7			/go/pkg/mod/github.com/davyxu/cellnet@v4.1.0+incompatible/pipe.go:48
#	0x8516bb	github.com/davyxu/cellnet.(*eventQueue).StartLoop.func1+0x7b	/go/pkg/mod/github.com/davyxu/cellnet@v4.1.0+incompatible/queue.go:87

1: 3719168 [1: 3719168] @ 0x8507c6 0x850b89 0x850f60 0x850f00 0x85b9ba 0x859306 0x922fb4 0x460391
#	0x8507c5	github.com/davyxu/cellnet.(*Pipe).Add+0xf5				/go/pkg/mod/github.com/davyxu/cellnet@v4.1.0+incompatible/pipe.go:17
#	0x850b88	github.com/davyxu/cellnet.(*eventQueue).Post+0x48			/go/pkg/mod/github.com/davyxu/cellnet@v4.1.0+incompatible/queue.go:57
#	0x850f5f	github.com/davyxu/cellnet.QueuedCall+0x3f				/go/pkg/mod/github.com/davyxu/cellnet@v4.1.0+incompatible/queue.go:155
#	0x850eff	github.com/davyxu/cellnet.SessionQueuedCall+0x7f			/go/pkg/mod/github.com/davyxu/cellnet@v4.1.0+incompatible/queue.go:147
#	0x85b9b9	github.com/davyxu/cellnet/proc.NewQueuedEventCallback.func1+0xc9	/go/pkg/mod/github.com/davyxu/cellnet@v4.1.0+incompatible/proc/procbundle.go:25
#	0x859305	github.com/davyxu/cellnet/peer.(*CoreProcBundle).ProcEvent+0x65		/go/pkg/mod/github.com/davyxu/cellnet@v4.1.0+incompatible/peer/procbundle.go:66
#	0x922fb3	github.com/davyxu/cellnet/peer/tcp.(*tcpSession).recvLoop+0x93		/go/pkg/mod/github.com/davyxu/cellnet@v4.1.0+incompatible/peer/tcp/session.go:151

1: 1212416 [1: 1212416] @ 0x8507c6 0x922dd1 0x85c3c6 0x934b46 0x936279 0x936246 0x85b8d7 0x850f74 0x850f00 0x85b9ba 0x859306 0x91c794 0x460391
#	0x8507c5	github.com/davyxu/cellnet.(*Pipe).Add+0xf5				/go/pkg/mod/github.com/davyxu/cellnet@v4.1.0+incompatible/pipe.go:17
#	0x922dd0	github.com/davyxu/cellnet/peer/tcp.(*tcpSession).Send+0x60		/go/pkg/mod/github.com/davyxu/cellnet@v4.1.0+incompatible/peer/tcp/session.go:91
#	0x85c3c5	GATE/src/game.(*Game).Send+0xc5						/app/src/game/game.go:56
#	0x934b45	GATE/src/server.(*ServerManager).onClientPacket+0x505			/app/src/server/servermanager.go:129
#	0x936278	GATE/src/server.(*Server).onClientPacket+0x98				/app/src/server/server.go:40
#	0x936245	GATE/src/server.(*Server).Init.func1+0x65				/app/src/server/server.go:28
#	0x85b8d6	github.com/davyxu/cellnet/proc.NewQueuedEventCallback.func1.1+0x36	/go/pkg/mod/github.com/davyxu/cellnet@v4.1.0+incompatible/proc/procbundle.go:27
#	0x850f73	github.com/davyxu/cellnet.QueuedCall+0x53				/go/pkg/mod/github.com/davyxu/cellnet@v4.1.0+incompatible/queue.go:153
#	0x850eff	github.com/davyxu/cellnet.SessionQueuedCall+0x7f			/go/pkg/mod/github.com/davyxu/cellnet@v4.1.0+incompatible/queue.go:147
#	0x85b9b9	github.com/davyxu/cellnet/proc.NewQueuedEventCallback.func1+0xc9	/go/pkg/mod/github.com/davyxu/cellnet@v4.1.0+incompatible/proc/procbundle.go:25
#	0x859305	github.com/davyxu/cellnet/peer.(*CoreProcBundle).ProcEvent+0x65		/go/pkg/mod/github.com/davyxu/cellnet@v4.1.0+incompatible/peer/procbundle.go:66
#	0x91c793	GATE/src/mytcp.(*tcpSession).recvLoop+0x93				/app/src/mytcp/session.go:152

1: 1212416 [1: 1212416] @ 0x8509e8 0x92342a 0x460391
#	0x8509e7	github.com/davyxu/cellnet.(*Pipe).Pick+0x1a7			/go/pkg/mod/github.com/davyxu/cellnet@v4.1.0+incompatible/pipe.go:48
#	0x923429	github.com/davyxu/cellnet/peer/tcp.(*tcpSession).sendLoop+0x59	/go/pkg/mod/github.com/davyxu/cellnet@v4.1.0+incompatible/peer/tcp/session.go:165

pprof显示这里有很大内存,请大神指点一下 谢谢

@davyxu
Copy link
Owner

davyxu commented Apr 28, 2021

你放到队列里的东西大, 当然显示内存大了.
writeList[0:0]的意思就是保留元素空间, 重置指针
如果泄露, 那每一个元素都会泄露

@davyxu
Copy link
Owner

davyxu commented Sep 6, 2021

已经用过的内存不重用, 有新数据就新申请内存?. 你是有多少钱买内存啊

@davyxu
Copy link
Owner

davyxu commented Sep 6, 2021

买本go的书看下吧, issue只提bug, 不教学

@davyxu davyxu closed this as completed Sep 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants