# How Computation Graph in PyTorch is created and freed?

**URL:** <https://discuss.pytorch.org/t/how-computation-graph-in-pytorch-is-created-and-freed/3515>\
**Category:** autograd\
**Created:** [May 29, 2017, 1:50pm UTC](https://discuss.pytorch.org/t/how-computation-graph-in-pytorch-is-created-and-freed/3515 "2017-05-29T13:50:01Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![zakizhou](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/zakizhou/32/2839_2.png) [@zakizhou](https://discuss.pytorch.org/u/zakizhou)\
**Post date:** [December 23, 2017, 4:05pm UTC](https://discuss.pytorch.org/t/how-computation-graph-in-pytorch-is-created-and-freed/3515/4 "2017-12-23T16:05:18Z")

</div>

@smth  
Thanks for your explanation, I have one more question, if I add retain\_graph=True in the following code, will all intermediary results in 100 graph exist in memory, or previous 99 graphs are freed and only the last graph exist in memory?  
import torch

```
for i in range(100):
    a = torch.autograd.Variable(torch.randn(2, 3).cuda(), requires_grad=True)
    y = torch.sum(a)
    y.backward(retain_graph=True)
```

---

_[View the full topic](https://discuss.pytorch.org/t/how-computation-graph-in-pytorch-is-created-and-freed/3515)._
