# Discarding unused AffExpr

**URL:** <https://discourse.julialang.org/t/discarding-unused-affexpr/17634>\
**Category:** Optimization (Mathematical)\
**Created:** [November 17, 2018, 8:47am UTC](https://discourse.julialang.org/t/discarding-unused-affexpr/17634 "2018-11-17T08:47:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vtjeng](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vtjeng/32/3787_2.png) [@vtjeng](https://discourse.julialang.org/u/vtjeng)\
**Post date:** [November 17, 2018, 8:47am UTC](https://discourse.julialang.org/t/discarding-unused-affexpr/17634/1 "2018-11-17T08:47:16Z")

</div>

As I’m creating my model in JuMP, I’m creating many `AffExprs` (~100k) but only a small fraction of them actually get used in constraints (I’m using interval arithmetic via [ConditionalJuMP.jl](https://github.com/rdeits/ConditionalJuMP.jl) to determine that the rest of the `AffExprs` would not be relevant).

Are these `AffExprs` possibly causing model creation to slow down, and if so, is there any way to indicate to JuMP that these `AffExprs` are unused?

---

<div class="post-metadata">

**Author:** ![miles.lubin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miles.lubin/32/279_2.png) [@miles.lubin](https://discourse.julialang.org/u/miles.lubin)\
**Post date:** [November 17, 2018, 3:44pm UTC](https://discourse.julialang.org/t/discarding-unused-affexpr/17634/2 "2018-11-17T15:44:31Z")

</div>

> [@vtjeng](#):
>
> Are these `AffExprs` possibly causing model creation to slow down

Of course creating them takes some time (which I recommend profiling). However, after they’re created they are never directly referenced when JuMP generates the data structures for the underlying solver. They will be garbage collected normally if there are no dangling references to them. If you can provide a standalone benchmark where JuMP model creation time is too slow we may be able to take a look.

The story for nonlinear expressions is different, but that’s not relevant to your question.
