# Excessive memory consumption when using powermod() with BigInt

**URL:** https://discourse.julialang.org/t/excessive-memory-consumption-when-using-powermod-with-bigint/71163
**Category:** General Usage
**Created:** [November 8, 2021, 5:20pm UTC](https://discourse.julialang.org/t/excessive-memory-consumption-when-using-powermod-with-bigint/71163 "2021-11-08T17:20:25Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![rbngz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rbngz/32/30604_2.png) [@rbngz](https://discourse.julialang.org/u/rbngz)
#### Post date: [November 8, 2021, 5:20pm UTC](https://discourse.julialang.org/t/excessive-memory-consumption-when-using-powermod-with-bigint/71163/1 "2021-11-08T17:20:25Z")

</div>

I want to brute force an 64-bit RSA encrypted text using a meet-in-the-middle attack (This is for university, nothing malicious).

To do this, I essentially created a Julia vector with 2^34 `BigInt` values and broadcasted the `powermod()` method on it to replace the values with the results.

```julia
v = powermod.((1:2^34), e, n)

```

`n` in this case is 1024-bits long which should theoretically result in a vector of 2^34 \* 1024 bits size plus overhead. However, if I try to create a smaller vector (E.g., 2^20) it will already allocate 4GB of memory.

```julia
const e = 65537
const n = 146524179203462820907751077702895222709717245613911342138636679265720963659264803540209990978140003809112749926543448691815554807130673470903067642157383639213843567573216381956709789503739105865173848988830139432801516289108538638198344024523424071181688467967187076534718264943427915623567859427045475866239

@time begin
    v = powermod.((1:2^24), e, n)
end

```

**Output of @time** :

```julia
125.598926 seconds (117.44 M allocations: 4.000 GiB, 5.35% gc time)

```

Apparently, the `powermod()` function requires quite a bit of memory when used with `BigInt` as modulo. Why is this memory not freed up after the value has been returned? Or am I doing something wrong?

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [November 8, 2021, 5:22pm UTC](https://discourse.julialang.org/t/excessive-memory-consumption-when-using-powermod-with-bigint/71163/2 "2021-11-08T17:22:39Z")

</div>

`@time` shows cumulative memory allocation during the execution of your code, so even if all memory is freed, it will show in the allocations count.

---

<div class="post-metadata">

### Author: ![rbngz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rbngz/32/30604_2.png) [@rbngz](https://discourse.julialang.org/u/rbngz)
#### Post date: [November 8, 2021, 5:24pm UTC](https://discourse.julialang.org/t/excessive-memory-consumption-when-using-powermod-with-bigint/71163/3 "2021-11-08T17:24:15Z")

</div>

Now I understand… Thanks again!
