()
| 252 | } |
| 253 | |
| 254 | func forceGC() { |
| 255 | var mem runtime.MemStats |
| 256 | runtime.ReadMemStats(&mem) |
| 257 | // It was empirically observed that without this extra allocation |
| 258 | // TestOperationLifetime would fail only 50% of the time if |
| 259 | // Operation did not hold on to a reference to Graph. With this |
| 260 | // additional allocation, and with the bug where Operation does |
| 261 | // not hold onto a Graph, the test failed 90+% of the time. |
| 262 | // |
| 263 | // The author is aware that this technique is potentially fragile |
| 264 | // and fishy. Suggestions for alternatives are welcome. |
| 265 | bytesTillGC := mem.NextGC - mem.HeapAlloc + 1 |
| 266 | _ = make([]byte, bytesTillGC) |
| 267 | runtime.GC() |
| 268 | debug.FreeOSMemory() |
| 269 | } |
no test coverage detected