All Projects → littledivy → drop

littledivy / drop

Licence: other
`drop` unwanted Deno resources out of memory. yeet.

Programming Languages

typescript
32286 projects

deno_drop

Manage your programs resource memory. Check out its impact on memory usage

Do not use in production - A lot of the code depends on internal Deno APIs that can change anytime. Intead, consider consuming your resources (like await response.arrayBuffer() on Response) to free up memory.

Impact

Here we have a long running loop pinging a local server. The request is stored as a resource in Deno's internal resource table.

import { drop, FetchResource } from "https://deno.land/x/[email protected]/mod.ts";

for (let i = 0; i < 1e4; i++) {
  await fetch("http://localhost:8000/images.png");
  // With `drop`              : 17.8mb
  // Without `drop` (default) : 200.1mb
  drop(FetchResource);
}

Doing this will create 10000 resources for every request made. Which can take up a LOT of memory.

By adding the drop(FetchResource), you will notice the memory consumption decrease drastically.

Examples

import {
  drop,
  TextDecoderResource,
} from "https://deno.land/x/[email protected]/mod.ts";

const decoder = new TextDecoder();
decoder.decode(new Uint8Array([1, 2, 3]), { stream: true });

drop(TextDecoderResource);
import { drop } from "https://deno.land/x/[email protected]/mod.ts";

const adapter = await navigator.gpu.requestAdapter();
const device = await adapter?.requestDevice();

drop(device);
drop(adapter);

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].