id,summary,reporter,owner,description,type,status,priority,milestone,component,version,resolution,keywords,cc
12,Unused array computations lead to memory leaks,tmcdonell,,"The CUDA backend uses explicit reference tracking for device arrays. However, if the result of a computation is not used, it may not be released until the entire CUDA environment is closed down. This is evident for computations under `Let2`, but may exist more generally. In the example below, we modify the `runCUDA` function display any active memory records on finalisation.

{{{
test_scan = do
  let xs :: Acc (Vector Int) = use $ fromList 10 [0..]
      expr = Acc.scanl (+) 0 xs

  putStrLn ""scan""
  print =<< CUDA.run (Prelude.fst expr)

  putStrLn ""reduction""
  print =<< CUDA.run (Prelude.snd expr)
}}}

Results in:

{{{
*Test> test_scan
scan
 91488264:=MemoryEntry {_refcount = 0, _memsize = 4, _arena = 1049088}

Array 10 [0,0,1,3,6,10,15,21,28,36]
reduction
 118558728:=MemoryEntry {_refcount = 0, _memsize = 40, _arena = 1048832}

Array () [45]
}}} ",defect,closed,major,,CUDA backend,0.8.0.0,fixed,,
