go-win64api
go-win64api copied to clipboard
Memory leak while using firewall.go
Hey @iamacarpet.
I'm trying to use a part of a package to control windows firewall.
It works well, but it doesn't release memory. For example, running functions in a loop will cause continuous incremental memory usage.
Looking at the library, it seems that this topic is taken care of(functions like firewallAPIRelease, firewallRulesEnumRealease).
Here's an example of code that replicates an issue.
package main
import (
"fmt"
winapi "github.com/kumako/go-win64api"
"time"
)
func main(){
var first string
for 1>0 {
fmt.Scanln(&first)
if first == "run"{
firewallTest()
}
}
}
func firewallTest(){
//get the list of the rules
ruleList, _ := winapi.FirewallRulesGet()
//delete them one by one using their names
for _, eachRule := range ruleList {
ruleName := eachRule.Name
if ruleName != ""{
winapi.FirewallRuleDelete(ruleName)
}
}
//wait for 30 second
time.Sleep(30 * time.Second)
//add them back, one by one, from the list
for _, eachRule := range ruleList{
winapi.FirewallRuleAddAdvanced(eachRule)
}
}
@pepperoni01 this is hopefully fixed by a PR submitted by @cuongvn98
Please let us know if we can close it
Unfortunately, memory leak still occurred while using the exact same code provided above. https://prnt.sc/nBBcBxH0LJXH (This was after just one "run" command, additional "run" commands continue to increase memory usage) https://prnt.sc/dLppMZK0iVBd (second "run")
Thanks for the update @pepperoni01
I’m not really going to be able to dedicate time to this myself, but perhaps @cuongvn98 might be happy to work with you?
Also a long shot, but have you tried forcing Go’s garbage collector to run between calls?
I think you can force it in the ‘runtime’ package, as I know from experience with other pieces of code that it will allow memory to rise dramatically if it is running on a high memory machine, before attempting to reap.
Yes, I've tried forcing Go's garbage collector. It does something, but not much. For comparison to previous screens, forcing garbage collectors resulted this outcome: 1st run: https://prnt.sc/9oT-45yrjcL7 2nd run: https://prnt.sc/6XaaM4vSu2SI
@pepperoni01 As my investigate all action as oleutil.GetProperty, ToIDispatch should be graceful release after use. It seem as memory of this variable is out of manage by Go .