package main import ( "fmt" "gob" "image" "os" ) type Card struct { Reverse map[int][]*image.Rectangle } func NewCard() *Card { c := new(Card) c.Reverse = make(map[int][]*image.Rectangle, 10) // 100 is about the smallest value that causes a leak on my machine. for i := 0; i < 100; i++ { c.Reverse[0] = append(c.Reverse[0], new(image.Rectangle)) c.Reverse[1] = append(c.Reverse[1], new(image.Rectangle)) c.Reverse[2] = append(c.Reverse[1], new(image.Rectangle)) // Note the different indexes. c.Reverse[4] = append(c.Reverse[1], new(image.Rectangle)) // Note the different indexes. c.Reverse[8] = append(c.Reverse[1], new(image.Rectangle)) // Note the different indexes. } return c } type Pile struct { Cards map[int]*Card VisableFragments map[int][]*image.Rectangle } func NewPile() *Pile { p := new(Pile) p.Cards = make(map[int]*Card, 10) for i := 0; i<500; i++ { p.Cards[i] = NewCard() } p.VisableFragments = make(map[int][]*image.Rectangle, 10) // 440 and 395 are about the smallest values that cause a memory leak on my machine. for i := 0; i<440; i++ { for j := 0; j<395; j++ { p.VisableFragments[i] = append(p.VisableFragments[i], new(image.Rectangle)) } } return p } func save(pile *Pile) os.Error { f, _ := os.Create("/tmp/gobble.gob") defer f.Close() encoder := gob.NewEncoder(f) return encoder.Encode(*pile) } func main() { pile := NewPile() for i := 0; i<10000000; i++ { fmt.Printf(".") save(pile) } }