zimmski/go-leak

语言: Go

git: https://github.com/zimmski/go-leak

检测Go中的各种泄漏
Detect all kinds of leaks in Go
README.md (中文)

去泄漏

Go的std包目前不包括泄漏检测。 go-leak是一个包,可以帮助您找到代码中的泄漏。如果您对如何改进此软件包有任何想法或有任何问题,请通过问题跟踪器提交问题。

注意:此软件包不再起作用。它适用于我使用较旧的Go版本的一些用例,但是> = 1.4它根本不起作用。我在我的TODO上重做了整个事情并添加了一些用例,但还有一些我必须先做的其他开源项目。因此,如果您有时间在手上,并希望向我发送邮件或在项目的跟踪器中提交问题。

注意:由于Go是作用域,因此避免与标记和释放调用具有相同范围的新变量非常重要。

够程

如果你想知道一个函数是否正在泄漏goroutines:

leaks := leak.GoRoutineLeaks(foo)

if leaks > 0 {
    panic("foo is leaking!")
}

如果你想知道代码是否泄漏了goroutines:

m := MarkGoRoutines()

// some code

leaks := m.Release()

if leaks > 0 {
    panic("some code is leaking!")
}

记忆

如果你想知道某个函数是否在泄漏内存:

leaks := leak.MemoryLeaks(foo)

if leaks > 0 {
    panic("foo is leaking!")
}

如果你想知道代码是否泄漏了内存:

m := MarkMemory()

// some code

leaks := m.Release()

if leaks > 0 {
    panic("some code is leaking!")
}

本文使用googletrans自动翻译,仅供参考, 原文来自github.com

en_README.md

go-leak GoDoc

The std packages of Go do currently not included detection for leaks. go-leak is a package which should help you find leaks in your code. If you have any ideas on how to improve this package or have problems of any kind with it, please submit an issue through the issue tracker.

Note: This package does not work anymore. It worked for some use-cases I had with an older Go version but with >= 1.4 it does not work at all. I have it on my TODO to redo the whole thing and add some more use-cases but there are some other open source projects I have to do first. So if you have some time on your hand and would like to contribute mail me or submit an issue in the project's tracker.

Note: Since Go is scoped it is important to avoid new variables that are in the same scope as the mark-and-release calls.

goroutines

If you want to know if a function is leaking goroutines:

leaks := leak.GoRoutineLeaks(foo)

if leaks > 0 {
    panic("foo is leaking!")
}

If you want to know if a code is leaking goroutines:

m := MarkGoRoutines()

// some code

leaks := m.Release()

if leaks > 0 {
    panic("some code is leaking!")
}

memory

If you want to know if a function is leaking memory:

leaks := leak.MemoryLeaks(foo)

if leaks > 0 {
    panic("foo is leaking!")
}

If you want to know if a code is leaking memory:

m := MarkMemory()

// some code

leaks := m.Release()

if leaks > 0 {
    panic("some code is leaking!")
}