我有关于内存泄漏的问题。 我的程序总是通过lib / pg从db查询数据,我发现内存泄漏问题。 我用pprof来调试问题发生的地方。
结果如下:
flat flat% sum% cum cum%
1.51MB 100% 100% 1.51MB 100% github.com/lib/pq.DialOpen
0 0% 100% 1.51MB 100% database/sql.(*DB).conn
0 0% 100% 1.51MB 100% database/sql.(*Stmt).Query
0 0% 100% 1.51MB 100% database/sql.(*Stmt).QueryContext
0 0% 100% 1.51MB 100% database/sql.(*Stmt).connStmt
0 0% 100% 1.51MB 100% github.com/lib/pq.(*Driver).Open
0 0% 100% 1.51MB 100% github.com/lib/pq.Open
0 0% 100% 1.51MB 100% github.com/traffic/traffic-worker/drivers/parking.(*BillGenerator).queryJobs
0 0% 100% 1.51MB 100% github.com/traffic/traffic-worker/drivers/pg.(*Client).QueryParkingRecordsByStatus
0 0% 100% 1.51MB 100% runtime.goexit
这是堆配置文件
heap profile: 4: 16384 [29: 2783280] @ heap/1048576
4: 16384 [4: 16384] @ 0x80dbf3 0x80d2f7 0x80c665 0x7fdab6 0x804296 0x8048e5 0x804dd5 0x830aea 0x85a028 0x45a9d1
0x80dbf2 github.com/lib/pq.DialOpen+0x8b2 /opt/gopath/src/github.com/lib/pq/conn.go:333
0x80d2f6 github.com/lib/pq.Open+0x66 /opt/gopath/src/github.com/lib/pq/conn.go:241
0x80c664 github.com/lib/pq.(*Driver).Open+0x34 /opt/gopath/src/github.com/lib/pq/conn.go:41
0x7fdab5 database/sql.(*DB).conn+0x145 /usr/local/go/src/database/sql/sql.go:965
0x804295 database/sql.(*Stmt).connStmt+0x1e5 /usr/local/go/src/database/sql/sql.go:1903
0x8048e4 database/sql.(*Stmt).QueryContext+0xe4 /usr/local/go/src/database/sql/sql.go:1941
0x804dd4 database/sql.(*Stmt).Query+0x64 /usr/local/go/src/database/sql/sql.go:1978
0x830ae9 github.com/traffic/traffic-worker/drivers/pg.(*Client).QueryParkingRecordsByStatus+0x2a9 /opt/gopath/src/github.com/traffic/traffic-worker/drivers/pg/pgClient.go:210
0x85a027 github.com/traffic/traffic-worker/drivers/parking.(*BillGenerator).queryJobs+0x107 /opt/gopath/src/github.com/traffic/traffic-worker/drivers/parking/parking.go:119
0: 0 [0: 0] @ 0x40adfa 0x80d459 0x80d2f7 0x80c665 0x7fdab6 0x804296 0x8048e5 0x804dd5 0x830aea 0x85a028 0x45a9d1
0x80d458 github.com/lib/pq.DialOpen+0x118 /opt/gopath/src/github.com/lib/pq/conn.go:258
0x80d2f6 github.com/lib/pq.Open+0x66 /opt/gopath/src/github.com/lib/pq/conn.go:241
0x80c664 github.com/lib/pq.(*Driver).Open+0x34 /opt/gopath/src/github.com/lib/pq/conn.go:41
0x7fdab5 database/sql.(*DB).conn+0x145 /usr/local/go/src/database/sql/sql.go:965
0x804295 database/sql.(*Stmt).connStmt+0x1e5 /usr/local/go/src/database/sql/sql.go:1903
0x8048e4 database/sql.(*Stmt).QueryContext+0xe4 /usr/local/go/src/database/sql/sql.go:1941
0x804dd4 database/sql.(*Stmt).Query+0x64 /usr/local/go/src/database/sql/sql.go:1978
0x830ae9 github.com/traffic/traffic-worker/drivers/pg.(*Client).QueryParkingRecordsByStatus+0x2a9 /opt/gopath/src/github.com/traffic/traffic-worker/drivers/pg/pgClient.go:210
0x85a027 github.com/traffic/traffic-worker/drivers/parking.(*BillGenerator)
那么如何解决这个内存泄漏问题呢?顺便问一下如何读取堆配置文件?谢谢你提前!