# Unexpected garbage collection when using append!

**URL:** <https://discourse.julialang.org/t/unexpected-garbage-collection-when-using-append/89732>\
**Category:** Performance\
**Tags:** question, garbage-collection\
**Created:** [November 3, 2022, 6:54pm UTC](https://discourse.julialang.org/t/unexpected-garbage-collection-when-using-append/89732 "2022-11-03T18:54:31Z")\
**Posts on this page:** 1\
**Page:** 2

<div class="post-metadata">

**Author:** ![jewh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jewh/32/28586_2.png) [@jewh](https://discourse.julialang.org/u/jewh)\
**Post date:** [November 4, 2022, 3:22pm UTC](https://discourse.julialang.org/t/unexpected-garbage-collection-when-using-append/89732/21 "2022-11-04T15:22:59Z")

</div>

The issue’s re-appeared. This time it only manifests after importing the package `Plots`:

```julia
julia> using BenchmarkTools

julia> function motif2(v::Vector{Vector{Float64}})     
           out = Vector{Float64}(undef, sum(length, v))
           offset = 0
           for vect in v
               for i ∈ eachindex(vect)
                   @inbounds out[offset + i] = vect[i] 
               end
               offset += lastindex(vect)
           end
           out
       end
motif2 (generic function with 1 method)

julia> vects = [rand(10) for i = 1:10];

julia> @benchmark motif2($vects)
BenchmarkTools.Trial: 10000 samples with 983 evaluations.
 Range (min … max): 61.343 ns … 1.403 μs ┊ GC (min … max): 0.00% … 65.96%
 Time (median): 76.399 ns ┊ GC (median): 0.00%
 Time (mean ± σ): 106.685 ns ± 90.701 ns ┊ GC (mean ± σ): 7.25% ± 9.22%

  ▃█▆▄▄▃▃▂▂▁▁▁▁▁ ▁
  ███████████████████▇▇▇▇▇▇▇▆▅▆▆▅▅▅▃▅▅▅▅▄▃▅▂▄▅▃▅▅▅▄▄▅▃▄▅▄▄▅▄▅▅ █
  61.3 ns Histogram: log(frequency) by time 559 ns <

 Memory estimate: 896 bytes, allocs estimate: 1.

julia> using Plots

julia> @benchmark motif2($vects)
BenchmarkTools.Trial: 5878 samples with 978 evaluations.
 Range (min … max): 70.654 ns … 59.460 μs ┊ GC (min … max): 0.00% … 99.52%
 Time (median): 83.027 ns ┊ GC (median): 0.00%
 Time (mean ± σ): 871.062 ns ± 6.223 μs ┊ GC (mean ± σ): 82.20% ± 11.33%

  █ ▁
  █▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▄▇ █
  70.7 ns Histogram: log(frequency) by time 54.2 μs <

 Memory estimate: 896 bytes, allocs estimate: 1.

```

However, unlike the previous issue, re-starting the REPL and not importing `Plots` fixes the issue.

[Previous page](https://discourse.julialang.org/t/unexpected-garbage-collection-when-using-append/89732.md?page=1)
