--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/dd5aba59-512c-4b9b-b365-2b509edd74e7n%40googlegroups.com.
to avoid false delete object, we could add some checking code in markDelete just like what we do with raceenable.
one complicate case is internal pointer, we could recursively mark delete or mark delete internal pointer by hand ?
problem is compiler often don't known how programs organize objects, or, some memory pattern could not be known at compile time.
and sometimes, delete point is very obvious in some programming models.
finally i think developer should take their risk taking some unsafe operations by himself (like rust lang?)
On Thu, May 27, 2021 at 10:36 PM cheng dong <qq451...@gmail.com> wrote:ok, i realized that it is unrealistic to add free operation in go.
i think i lack some knowledge of how gc works. may i have a question, if it is obvious to go compiler when a object got no reference why go only collect memory in gc steps instead of collect immediately after object got no reference?You only replied to me, not the golang-nuts mailing list. As a general rule you should not do that.If it is obvious to the Go compiler "a object got no reference" the compiler will place the object on the goroutine stack rather than in the heap. Assuming, of course, that the object has a size reasonable for placement on the stack. Therefore not requiring the intervention of the Go garbage collector.
Thank you for the clarification.
sorry to break the general rule, i'm new to golang-nuts
as to the question, i figured out i used wrong words, what i need in fact is1. a hint to tell compiler that some object are safe to alloc on stack(in case that we use it as interface so it escape from stack) 2. some concept like unique ptr that when it end it's life time, the object referenced can be deallocated immediately.