# Dfx deploy --network=ic heap out of bounds

**URL:** <https://forum.dfinity.org/t/dfx-deploy-network-ic-heap-out-of-bounds/6031>\
**Category:** Developers\
**Created:** [July 21, 2021, 2:44pm UTC](https://forum.dfinity.org/t/dfx-deploy-network-ic-heap-out-of-bounds/6031 "2021-07-21T14:44:27Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![avi](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/avi/32/1904_2.png) [@avi](https://forum.dfinity.org/u/avi)\
**Post date:** [July 21, 2021, 2:44pm UTC](https://forum.dfinity.org/t/dfx-deploy-network-ic-heap-out-of-bounds/6031/1 "2021-07-21T14:44:27Z")

</div>

The invocation to the wallet call forward method failed with the error: An error happened during the call: 5: Canister “canister-id” trapped: heap out of bounds

Appeared for the first time? What do i do

---

<div class="post-metadata">

**Author:** ![avi](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/avi/32/1904_2.png) [@avi](https://forum.dfinity.org/u/avi)\
**Post date:** [July 21, 2021, 3:10pm UTC](https://forum.dfinity.org/t/dfx-deploy-network-ic-heap-out-of-bounds/6031/2 "2021-07-21T15:10:34Z")

</div>

Is there anyone? please help me

---

<div class="post-metadata">

**Author:** ![anon74414410](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@anon74414410](https://forum.dfinity.org/u/anon74414410)\
**Post date:** [July 21, 2021, 3:39pm UTC](https://forum.dfinity.org/t/dfx-deploy-network-ic-heap-out-of-bounds/6031/3 "2021-07-21T15:39:25Z")

</div>

I can’t really answer in the abstract - can you document the dfx version, the call you were trying to make, your OS, and whether you have upgraded your cycles wallet recently?

---

<div class="post-metadata">

**Author:** ![avi](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/avi/32/1904_2.png) [@avi](https://forum.dfinity.org/u/avi)\
**Post date:** [July 21, 2021, 3:48pm UTC](https://forum.dfinity.org/t/dfx-deploy-network-ic-heap-out-of-bounds/6031/5 "2021-07-21T15:48:55Z")

</div>

dfx version 0.7.2  
Mac Os 11.4  
dfx canister --network=ic status “Canister Name”  
Canister status call result for “Canister Name”  
Status: Running

dfx deploy --network=ic

Deploying all canisters.  
All canisters have already been created.  
Building canisters…  
…

Upgrading code for canister “Canister Name”, with canister\_id “canisterId”  
The invocation to the wallet call forward method failed with the error: An error happened during the call: 5: Canister “canisterId” trapped: heap out of bounds

Controller: r34ha-yiaaa-aaaah-aaa4q-cai  
Memory allocation: 0  
Compute allocation: 0  
Freezing threshold: 2\_592\_000  
Memory Size: Nat(BigUint { data: [56467965] })  
Balance: 56\_206\_146\_962\_072 Cycles  
Module hash: 0x969171e08c4e6c60b54d889e3a733efbbdedfbc30536bcafbf0b6e892c68bbb7

---

<div class="post-metadata">

**Author:** ![ccyanxyz](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/ccyanxyz/32/1025_2.png) [@ccyanxyz](https://forum.dfinity.org/u/ccyanxyz)\
**Post date:** [August 12, 2021, 3:22am UTC](https://forum.dfinity.org/t/dfx-deploy-network-ic-heap-out-of-bounds/6031/6 "2021-08-12T03:22:15Z")

</div>

Any news on this? I got the same error when upgrade my canister.

---

<div class="post-metadata">

**Author:** ![avi](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/avi/32/1904_2.png) [@avi](https://forum.dfinity.org/u/avi)\
**Post date:** [August 12, 2021, 12:25pm UTC](https://forum.dfinity.org/t/dfx-deploy-network-ic-heap-out-of-bounds/6031/7 "2021-08-12T12:25:34Z")

</div>

no,

There is no way to contact the corresponding person to deal with it. At present, we also leave this container in a free state.

---

<div class="post-metadata">

**Author:** ![flyq](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/flyq/32/3637_2.png) [@flyq](https://forum.dfinity.org/u/flyq)\
**Post date:** [August 13, 2021, 3:40am UTC](https://forum.dfinity.org/t/dfx-deploy-network-ic-heap-out-of-bounds/6031/8 "2021-08-13T03:40:44Z")

</div>

> [@avi](#):
>
> Memory allocation: 0  
> Compute allocation: 0

Why Memory allocation is 0?

---

<div class="post-metadata">

**Author:** ![avi](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/avi/32/1904_2.png) [@avi](https://forum.dfinity.org/u/avi)\
**Post date:** [August 13, 2021, 8:24am UTC](https://forum.dfinity.org/t/dfx-deploy-network-ic-heap-out-of-bounds/6031/9 "2021-08-13T08:24:23Z")

</div>

system auto allocation  
No manual adjustment

---

<div class="post-metadata">

**Author:** ![y-ang2010](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/y-ang2010/32/1014_2.png) [@y-ang2010](https://forum.dfinity.org/u/y-ang2010)\
**Post date:** [January 26, 2022, 3:41am UTC](https://forum.dfinity.org/t/dfx-deploy-network-ic-heap-out-of-bounds/6031/10 "2022-01-26T03:41:03Z")

</div>

I got the same issue.  
It’s the reason : HashMap too big ?  
It’s any way to find the reason?

my dfx version 0.8.4  
 ![image](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/2X/e/e3ca2b064c0edf7dd9b039598f79d93a01b91be1.jpeg)

```
        heap_size = Prim.rts_heap_size();
        memory_size = Prim.rts_memory_size();
        max_live_size = Prim.rts_max_live_size();
        total_allocation = Prim.rts_total_allocation();
        reclaimed = Prim.rts_reclaimed();
        rts_version = Prim.rts_version();
        cycles = Cycles.balance();
```

---

<div class="post-metadata">

**Author:** ![PaulLiu](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/paulliu/32/4701_2.png) [@PaulLiu](https://forum.dfinity.org/u/PaulLiu)\
**Post date:** [January 27, 2022, 3:15am UTC](https://forum.dfinity.org/t/dfx-deploy-network-ic-heap-out-of-bounds/6031/11 "2022-01-27T03:15:06Z")

</div>

I ran into this error last week. First of all, what I describe below may not be the only cause of this error. With that in mind, please read on…

I ran into “heap out of bounds” when trying to upgrade a motoko canister. It turned out that the error was caused by incompatible types of my stable variable. ~~I think the next release of dfx will have better error messages that actually prevent you from doing the upgrade when such an incompatibility is detected, instead of allowing your upgrade request to be sent and then got a runtime error back.~~ I might have jumped the gun, this may not be ready yet…

In any case, it should be easy to understand that why one can’t automatically upgrade  
`stable var i : Int = ... ` to `stable var j : Nat = ...` . In other words, old value of a stable variable may not satisfy its new type. So there is an entire set of subtype rules to help check this.

It is however not an easy task to check manually when your type is more complex. For example, one is allowed to add a new field to a record as long as the new field has an option type. This is okay, but I was adding a mutable field `var name = ....`, then this is not okay! I ran into “heap out of bound” error due to this. Eventually I resolved this problem by doing a conversion between old and new type in the `postupgrade()` function.

It is actually better to run into errors during upgrade. It is much worse when the upgrade went through and yet data is lost in stable variables! It can also happen! This is why I think it is crucial to have automatic checks on type compatibility of stable variables before attempting an upgrade.

Hope it helps!

---

<div class="post-metadata">

**Author:** ![y-ang2010](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/y-ang2010/32/1014_2.png) [@y-ang2010](https://forum.dfinity.org/u/y-ang2010)\
**Post date:** [January 28, 2022, 9:05am UTC](https://forum.dfinity.org/t/dfx-deploy-network-ic-heap-out-of-bounds/6031/12 "2022-01-28T09:05:52Z")

</div>

Thanks for your help .

Some thing wrong in my code , I used some reference variables,when canister upgrade it will change temp variables to stable [reference variables], then temp variables will be cleared, and the reference variables lost.

```auto
type DataStruct = {
	titleIdx : Nat;
	var count : Nat;
	var datas : List.List<Text>;
};
private var stableDataArray : [DataStruct] = [];
private var tmpTBTree = RBT.RBTree<Nat, DataStruct>(Nat.compare);
system preupgrade() {
    stableDataArray := Array.map<(Nat,DataStruct), DataStruct>(Iter.toArray(tmpTBTree.entries()) , func(x :(Nat,DataStruct) ) : (DataStruct) {x.1}) ;
};
system postupgrade() {
    for(v in stableDataArray.vals()){tmpTBTree.put(v.titleIdx, v)};
};

```

So I changed DataStruct and fix it.

```auto
type DataStructImmu = {
        titleIdx : Nat;
        count : Nat;
        datas : [Text];
};

```
