@@ -427,8 +427,9 @@ func gc(goplsDir string) {
427
427
for {
428
428
// Enumerate all files in the cache.
429
429
type item struct {
430
- path string
431
- stat os.FileInfo
430
+ path string
431
+ mtime time.Time
432
+ size int64
432
433
}
433
434
var files []item
434
435
start := time .Now ()
@@ -454,7 +455,7 @@ func gc(goplsDir string) {
454
455
}
455
456
os .Remove (path ) // ignore error
456
457
} else {
457
- files = append (files , item {path , stat })
458
+ files = append (files , item {path , stat . ModTime (), stat . Size () })
458
459
total += stat .Size ()
459
460
if debug && len (files )% 1000 == 0 {
460
461
log .Printf ("filecache: checked %d files in %v" , len (files ), time .Since (start ))
@@ -469,7 +470,7 @@ func gc(goplsDir string) {
469
470
470
471
// Sort oldest files first.
471
472
sort .Slice (files , func (i , j int ) bool {
472
- return files [i ].stat . ModTime (). Before (files [j ].stat . ModTime () )
473
+ return files [i ].mtime . Before (files [j ].mtime )
473
474
})
474
475
475
476
// Delete oldest files until we're under budget.
@@ -479,13 +480,14 @@ func gc(goplsDir string) {
479
480
break
480
481
}
481
482
if debug {
482
- age := time .Since (file .stat . ModTime () )
483
+ age := time .Since (file .mtime )
483
484
log .Printf ("budget: deleting stale file %s (%dB, age %v)" ,
484
- file .path , file .stat . Size () , age )
485
+ file .path , file .size , age )
485
486
}
486
487
os .Remove (file .path ) // ignore error
487
- total -= file .stat . Size ()
488
+ total -= file .size
488
489
}
490
+ files = nil // release memory before sleep
489
491
490
492
time .Sleep (period )
491
493
0 commit comments