# Why is inplace addition to array slice allocating?

**URL:** <https://discourse.julialang.org/t/why-is-inplace-addition-to-array-slice-allocating/103214>\
**Category:** General Usage\
**Created:** [August 26, 2023, 1:00am UTC](https://discourse.julialang.org/t/why-is-inplace-addition-to-array-slice-allocating/103214 "2023-08-26T01:00:58Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Kangaa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kangaa/32/51765_2.png) [@Kangaa](https://discourse.julialang.org/u/Kangaa)\
**Post date:** [August 26, 2023, 3:05am UTC](https://discourse.julialang.org/t/why-is-inplace-addition-to-array-slice-allocating/103214/2 "2023-08-26T03:05:00Z")

</div>

I think it is because

```julia
foo[1,:,1] .+= 2

```

expands to

```julia
foo[1,:,1] .= foo[1,:,1] .+ 2

```

so a copy of the slice is assigned.  
see: [Allocation when assigning to a slice](https://discourse.julialang.org/t/allocation-when-assigning-to-a-slice/73381)

---

_[View the full topic](https://discourse.julialang.org/t/why-is-inplace-addition-to-array-slice-allocating/103214)._
