Delete Objects
Delete is a soft delete: the object disappears from your app's listings, and any slab it referenced is unpinned immediately if no other object still points to it. Slabs can be shared between objects, so a slab only becomes eligible for host cleanup once every object referencing it has been deleted.
prune_slabs() is a reconciliation sweep, not the primary cleanup path — deletion already releases unreferenced slabs on its own. Use it to catch slabs orphaned by interrupted uploads or other edge cases. It only considers slabs pinned more than 72 hours ago, so a slab orphaned moments ago is deliberately left alone — pruning too eagerly risks destroying data for an upload that's still in flight.
use sia_storage::Hash256;
use std::str::FromStr;
let object_id = Hash256::from_str("your-object-id-here")?;
sdk.delete_object(&object_id).await?;
println!("Object deleted.");var objectID types.Hash256
if err := objectID.UnmarshalText([]byte("your-object-id-here")); err != nil {
panic(err)
}
if err := client.DeleteObject(ctx, objectID); err != nil {
panic(err)
}
fmt.Println("Object deleted.")await sdk.delete_object(object_id)
print("Object deleted.")import 'package:sia_storage/sia_storage.dart';
await sdk.deleteObject(key: objectId);
print('Object deleted.');await sdk.deleteObject(objectId)
console.log('Object deleted.')await sdk.deleteObject(objectId)
console.log('Object deleted.')Running the reconciliation sweep
Most apps never need to call this — deletion already frees a slab once nothing references it. Run prune_slabs() periodically, or after a batch of deletes, to catch slabs orphaned by interrupted uploads or other edge cases:
sdk.prune_slabs().await?;
println!("Unused slabs pruned.");if err := client.PruneSlabs(ctx); err != nil {
panic(err)
}
fmt.Println("Unused slabs pruned.")await sdk.prune_slabs()
print("Unused slabs pruned.")await sdk.pruneSlabs();
print('Unused slabs pruned.');await sdk.pruneSlabs()
console.log('Unused slabs pruned.')await sdk.pruneSlabs()
console.log('Unused slabs pruned.')Overriding the prune cutoff
Only the Go SDK exposes the prune cutoff directly:
⚠️ Warning
Lowering the cutoff below the default 72 hours increases the risk of pruning a slab whose upload hasn't finished yet. Only use a window this short if every upload is guaranteed to complete well within it — the 30-minute value below is illustrative, not a recommendation.
import (
"time"
"go.sia.tech/indexd/api"
)
// Only prune slabs pinned more than 30 minutes ago instead of the default 72 hours.
if err := client.PruneSlabs(ctx, api.WithBefore(time.Now().Add(-30*time.Minute))); err != nil {
panic(err)
}Rust and Python prune_slabs(), and Dart and JavaScript pruneSlabs(), take no arguments and always use the indexer's default 72-hour cutoff.
