On Tuesday, April 16, 2013 12:06:36 AM UTC-6, Raheel Gupta wrote:
Maybe, but I still feel having an option to free memory anytime alongwith
the GC would be a better solution. I love the GC, but something to free the
memory would always be handy.
For now, seasoned gophers are pretty good at avoiding garbage where it
matters, and not caring where it doesn't. See
http://blog.golang.org/2011/06/profiling-go-programs.html.Just like you should profile to make sure you need it before you spend
effort optimizing, you should profile before you come to the conclusion
that you need to explicitly free things. One of the strategies that has
kept Go from mutating into C++ is to avoid extending the language or
standard libs with anything that could eventually be done by the runtime or
the compiler, even though it may need suboptimal code is being generated
now.
Looking to the future, there are a great many tangible compiler
optimization opportunities, even within the current mark/sweep collector
approach (other collectors have been discussed at length elsewhere):
- Fixed-size allocations, such as `new(struct{...})`, which don't escape
are currently allocated on the stack.
- Variable-size allocations (slices, maps), which don't escape could be
freed on stack pop.
- Running functions that don't access non-local memory would not need to
stop for garbage collection. They would only need to pause at a stack
boundary when:
1. Calling into a function that shares memory
2. Unrolling back into a function that shares memory
3. (the bottom/frozen portion of a goroutine stack could thus be
scanned even while the top of the same stack is 'hot')
4. Channels holding fixed size "value" data could also count as
non-escaping for the above purpose, and the channels themselves could get
allocated in a delayed collection arena.
Besides, giving people the ability to free memory would lead to abuse; for
one thing, we'd get mailing list questions asking why the compiler wouldn't
allow `var x int; free(x)`.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/groups/opt_out.