I am not sure I understand what is going on here. For reference, the relevant code is:
String s = "This is a test string"; MyStruct struct = new MyStruct(s.getBytes("UTF-8")); //struct.setE(s.getBytes("UTF-8")); tv.append("\nFirst time: "+ new String(struct.getE(), "UTF-8")); with corresponding go part: package test type MyStruct struct{ E []byte} func NewMyStruct(e []byte) *MyStruct{ return &MyStruct{e}} so s.getBytes allocates a new byte[] (in Java). Then the MyStruct constructor is called, and it gets a reference to such byte[]. Are you saying that since the Java garbage collector is not aware that a reference to that array is stored in some variable in the go code, then it just deletes it as soon as the constructor returns? And then the getE method just reads whatever happens to be in memory where the old array was without throwing any error despite the fact that the old byte[] has been garbage collected and might have been overwritten by arbitrary data? Thanks a lot for your response! Antonio On Wednesday, August 2, 2017 at 3:30:06 PM UTC-7, Elias Naur wrote: > > []byte arguments are passed by reference, not copied. You need to copy any > byte slices you retain after the function or method call. > > - elias > -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.