Menu

Post image 1
Post image 2
Post image 3
1 / 3
0

đŸ‘» The Ghost of the Ancestor: A Memory Horror Story in Go, Java, and Rust

DEV Community·Satyadev Neti·about 1 month ago
#n9ioIGd0
#go#java#rust#scores1#scores2#myscores
Reading 0:00
15s threshold

In the world of high-performance programming, we are obsessed with Slices. We want to take a small piece of a large dataset without copying it. It’s fast. It’s efficient. But it’s haunted. Let’s look at how three of the world's most popular languages deal with the "Ghost of the Ancestor"—the phenomenon where a tiny "descendant" slice keeps a massive "ancestor" array alive in memory forever. The Setup: Go’s "Hidden" Connection In Go, a slice is just a small header pointing to a big array. Notice how scores2 is built from scores1 . package main import "fmt" func main () { // Original Go Logic scores := make ([] int , 0 , 5 ) scores1 := make ([] int , 0 , 5 ) scores2 := make ([] int , 0 , 5 ) scores = append ( scores , 234 , 242 , 53 , 42 , 353 ) fmt . Println ( "Scores : " , scores , len ( scores )) scores1 = append ( scores1 , 234 , 242 , 53 , 42 , 353 , 1111 ) fmt . Println ( "Scores1 : " , scores1 , len ( scores1 )) // Here Slices grow itself, but they still share an ancestor!


Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More