测试内存泄露问题
This commit is contained in:
parent
8c382bbbff
commit
539ea9215b
|
|
@ -195,13 +195,11 @@ func subscribeAndHandleMessagesV5(ws *websocket.Conn, deviceId int) {
|
|||
count := 0
|
||||
//定时器,发送计数器
|
||||
tCount := 0
|
||||
var buf []byte
|
||||
buf := make([]byte, 1024)
|
||||
//计算帧率
|
||||
for {
|
||||
//将buf置空
|
||||
buf = nil
|
||||
//从service获取当前帧
|
||||
c := service.GetDeviceCurrentFrameV5(deviceId, count, &buf)
|
||||
c := service.GetDeviceCurrentFrameV5(deviceId, count, buf)
|
||||
if c != count {
|
||||
count = c
|
||||
err2 := ws.WriteMessage(websocket.BinaryMessage, buf)
|
||||
|
|
@ -233,9 +231,6 @@ func subscribeAndHandleMessagesV5(ws *websocket.Conn, deviceId int) {
|
|||
worker.SetRedisWithExpire(strconv.Itoa(deviceId)+"_is_play", "1", time.Minute*5)
|
||||
log.Printf("device_id: %d has set is_play to 0", deviceId)
|
||||
}
|
||||
|
||||
//垃圾回收
|
||||
runtime.GC()
|
||||
}
|
||||
|
||||
func subscribeAndHandleMessagesV3(ws *websocket.Conn, deviceId int) {
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ func SetDeviceCurrentFrameV2(frame *gocv.Mat, deviceId int) error {
|
|||
DeviceFrameCount[deviceId] = frameCount
|
||||
return nil
|
||||
}
|
||||
func GetDeviceCurrentFrameV5(deviceId int, curCount int, buf *[]byte) (cnt int) {
|
||||
func GetDeviceCurrentFrameV5(deviceId int, curCount int, buf []byte) (cnt int) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
log.Printf("设备:%d 错误: %v\n", deviceId, err)
|
||||
|
|
@ -143,7 +143,7 @@ func GetDeviceCurrentFrameV5(deviceId int, curCount int, buf *[]byte) (cnt int)
|
|||
}
|
||||
// 避免直接返回大数组,可考虑复制必要的数据
|
||||
if len(tempBuf) > 0 {
|
||||
copy(*buf, tempBuf)
|
||||
copy(buf, tempBuf)
|
||||
// 释放临时变量
|
||||
tempBuf = nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue