Failed deleting canister on mainnet

Hello, when I tried to delete this canister on mainnet it always gives me this error, how can I delete canister on mainnet and what this error means?

Command: dfx canister delete icrc1_ledger_canister --network=ic

Error:
Beginning withdrawal of cycles; on failure try --no-wallet --no-withdrawal.
WARNING!
Canister icrc1_ledger_canister has not been stopped. Delete anyway?
Do you want to proceed? yes/No
y
Setting the controller to identity principal.
Installing temporary wallet in canister icrc1_ledger_canister to enable transfer of cycles.
Attempting to transfer 2191853153265 cycles to canister zhdv6-haaaa-aaaan-qzmsq-cai.
Error: Failed to delete canister ‘icrc1_ledger_canister’.
Caused by: Failed to delete canister ‘icrc1_ledger_canister’.
Failed to deposit 2191853153265 cycles into zhdv6-haaaa-aaaan-qzmsq-cai.
Failed to call update function ‘deposit_cycles’ regarding canister ‘zhdv6-haaaa-aaaan-qzmsq-cai’.
Update call using wallet failed.
The replica returned a rejection error: reject code CanisterError, reject message Error from Canister 7p6gu-biaaa-aaaap-aknta-cai: Canister 7p6gu-biaaa-aaaap-aknta-cai is out of cycles, error code None

It means that dfx is trying to recover too many cycles. I’ve tried a few times to make this work automatically. It’s been painful…

To make this work, use --initial-margin <cycles amount> with increasing numbers until it works. I would start with --initial-margin 100b and increase by 50b until it works

Do you mean I should add cycles to my canister?

No, you should (manually) leave more cycles in the canister when deleting. Not all cycles can be extracted because of how the protocol works. I’ve unsuccessfully tried to minimize that as much as possible for way too much time and have found no better solution yet.

With --initial-margin you specify how many cycles should be left in the canister before deleting it. If the margin is large enough it will succeed in withdrawing excess cycles. If the margin is too large you will unnecessarily delete cycles.