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

Memory leak while using firewall.go #39

Open
pepperoni01 opened this issue Jun 28, 2021 · 5 comments
Open

Memory leak while using firewall.go #39

pepperoni01 opened this issue Jun 28, 2021 · 5 comments

Comments

@pepperoni01
Copy link

pepperoni01 commented Jun 28, 2021

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)
    }
}

@iamacarpet
Copy link
Owner

@pepperoni01 this is hopefully fixed by a PR submitted by @cuongvn98

Please let us know if we can close it

@pepperoni01
Copy link
Author

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")

@iamacarpet
Copy link
Owner

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.

@pepperoni01
Copy link
Author

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

@hirosumee
Copy link

@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 .

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

3 participants