# Problems with deleting a canister

**URL:** <https://forum.dfinity.org/t/problems-with-deleting-a-canister/30646>\
**Category:** Command Line Tools\
**Created:** [May 11, 2024, 6:49pm UTC](https://forum.dfinity.org/t/problems-with-deleting-a-canister/30646 "2024-05-11T18:49:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![richards](https://avatars.discourse-cdn.com/v4/letter/r/7ba0ec/32.png) [@richards](https://forum.dfinity.org/u/richards)\
**Post date:** [May 11, 2024, 6:49pm UTC](https://forum.dfinity.org/t/problems-with-deleting-a-canister/30646/1 "2024-05-11T18:49:18Z")

</div>

when i try to delete a (stopped) canister, i get the result below.

How do i delete a canister and retrieve the cycles?

```auto
dfx canister delete Bazar_backend --ic
Please enter the passphrase for your identity: [hidden]
Decryption complete.
Beginning withdrawal of cycles; on failure try --no-wallet --no-withdrawal.
Setting the controller to identity principal.
Installing temporary wallet in canister Bazar_backend to enable transfer of cycles.
Attempting to transfer 2969289990002 cycles to canister zwmuh-ziaaa-aaaan-qelaa-cai.
Error: Failed to delete canister 'Bazar_backend'.
Caused by: Failed to delete canister 'Bazar_backend'.
  Failed to deposit 2969289990002 cycles into zwmuh-ziaaa-aaaan-qelaa-cai.
    Failed to call update function 'deposit_cycles' regarding canister 'zwmuh-ziaaa-aaaan-qelaa-cai'.
      Update call using wallet failed.
        The replica returned a replica error: reject code CanisterError, reject message Error from Canister ez4fu-xiaaa-aaaan-qmbra-cai: Canister ez4fu-xiaaa-aaaan-qmbra-cai is out of cycles, error code None

```

when i check the staus, the canister has started again and about 0.005T cycles are gone

```auto
dfx canister status --all --ic
Please enter the passphrase for your identity: [hidden]
Decryption complete.
Canister status call result for Bazar_backend.
Status: Running
Controllers: j6c6e-4p2az-veznb-gbwom-w3rma-54dcj-ol4lz-3hcex-b2xxw-y5sok-lae
Memory allocation: 0
Compute allocation: 0
Freezing threshold: 0
Memory Size: Nat(3677184)
Balance: 2_979_892_571_787 Cycles
Reserved: 0 Cycles
Reserved Cycles Limit: 5_000_000_000_000 Cycles
Module hash: 0xc1290ad65e6c9f840928637ed7672b688216a9c1e919eacbacc22af8c904a5e3
Number of queries: 0
Instructions spent in queries: 0

```

---

<div class="post-metadata">

**Author:** ![jennifertran](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jennifertran/32/11558_2.png) [@jennifertran](https://forum.dfinity.org/u/jennifertran)\
**Post date:** [May 11, 2024, 11:54pm UTC](https://forum.dfinity.org/t/problems-with-deleting-a-canister/30646/2 "2024-05-11T23:54:52Z")

</div>

What `dfx` version are you using? Have you upgraded to version `0.20.0`?

---

<div class="post-metadata">

**Author:** ![richards](https://avatars.discourse-cdn.com/v4/letter/r/7ba0ec/32.png) [@richards](https://forum.dfinity.org/u/richards)\
**Post date:** [May 12, 2024, 6:29am UTC](https://forum.dfinity.org/t/problems-with-deleting-a-canister/30646/3 "2024-05-12T06:29:52Z")

</div>

Yes, i upgraded to 0.20.0

---

<div class="post-metadata">

**Author:** ![jennifertran](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jennifertran/32/11558_2.png) [@jennifertran](https://forum.dfinity.org/u/jennifertran)\
**Post date:** [May 12, 2024, 6:54am UTC](https://forum.dfinity.org/t/problems-with-deleting-a-canister/30646/4 "2024-05-12T06:54:05Z")

</div>

Thank you for the confirmation. We will check and get back to you.

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [May 13, 2024, 11:20am UTC](https://forum.dfinity.org/t/problems-with-deleting-a-canister/30646/5 "2024-05-13T11:20:15Z")

</div>

That’s a problem with dfx. Sorry about that. I know how to solve it but haven’t gotten around to fixing it yet.

Workaround for the meantime:  
Call `dfx canister --wallet <canister to delete> deposit-cycles --ic $(dfx identity --ic get-wallet) <cycles amount>`. This will use the wallet that was installed in the canister you want to delete to send cycles to your actual cycles wallet. Given that you have 2.9T cycles in your canister you probably can use `2.8T` or `2.7T` in place of `<cycles amount`.  
After withdrawing cycles manually you should be able to delete the canister with the `--no-withdrawal` flag, which will not try to withdraw cycles

---

<div class="post-metadata">

**Author:** ![asjn3e](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/asjn3e/32/22792_2.png) [@asjn3e](https://forum.dfinity.org/u/asjn3e)\
**Post date:** [May 13, 2024, 1:12pm UTC](https://forum.dfinity.org/t/problems-with-deleting-a-canister/30646/6 "2024-05-13T13:12:12Z")

</div>

Does that also include withdrawing frozen threshold?

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [May 13, 2024, 1:21pm UTC](https://forum.dfinity.org/t/problems-with-deleting-a-canister/30646/7 "2024-05-13T13:21:49Z")

</div>

Yes. `dfx` sets the freezing threshold to 0 before attempting to withdraw, so any previously reserved cycles are free to withdraw
