panjf2000 / ants

🐜🐜🐜 ants is the most powerful and reliable pooling solution for Go.
https://ants.andypan.me/
MIT License
12.69k stars 1.36k forks source link

[Feature]: 144bytes allocated consistently just using ants.Submit( without doing anything #316

Closed kolinfluence closed 5 months ago

kolinfluence commented 5 months ago

Description of new feature

144bytes alloc doing nothing, can iron it out? how to make it 0?

./memalloc Alloc = 139824 B TotalAlloc = 139824 B Sys = 6380560 B NumGC = 0 Alloc = 141208 B TotalAlloc = 141208 B Sys = 6380560 B NumGC = 0 Alloc = 141368 B TotalAlloc = 141368 B Sys = 6380560 B NumGC = 0 Alloc = 141512 B TotalAlloc = 141512 B Sys = 6380560 B NumGC = 0 Alloc = 141672 B TotalAlloc = 141672 B Sys = 6380560 B NumGC = 0

package main

import (
        "time"
        "github.com/cloudxaas/gosysinfo/mem"   //go get -u github.com/cloudxaas/gosysinfo/mem@7a71da0

        "github.com/panjf2000/ants/v2"
)

func main() {

        ants.Submit(func() { //this doesnt work
                cxsysinfomem.LogMemStatsPeriodically(3 * time.Second)
        })

        select {}
}

Scenarios for new feature

zero memory allocation when idle

Breaking changes or not?

No

Code snippets (optional)

No response

Alternatives for new feature

None.

Additional context (optional)

None.

panjf2000 commented 5 months ago

If you don't want the default pool, just call Release()/ReleaseTimeout() to close it.

kolinfluence commented 5 months ago

@panjf2000 can you update this example where it doesnt have any mem allocated when doing nothing?

package main

import (
        "time"
        "github.com/cloudxaas/gosysinfo/mem"   //go get -u github.com/cloudxaas/gosysinfo/mem@7a71da0

        "github.com/panjf2000/ants/v2"
)

func main() {

        ants.Submit(func() { //this doesnt work
                cxsysinfomem.LogMemStatsPeriodically(3 * time.Second)
        })

        select {}
}