
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
Weak references are great, but nearly nothing truly uses it in javascript.
Why not just use WeakSet? A native WeakSet is write only, you cant do things like .forEach or for (const value of set). The only thing it can be used for is seeing if it contains it.
import {WeakRefSet} from "weakrefset";
class Clients {
constructor(private readonly server: Server) {
}
doSomething() {
}
}
class Server {
clients = new WeakRefSet<Client>();
}
function test() {
const server = new Server();
const clientA = new Client(server);
const clientB = new Client(server);
server.clients.add(clientA).add(clientB);
server.clients.forEach(client => client.doSomething());
}
test();
If this code was written with a normal new Set<Client>, everything would float forever in memory and never be cleaned. As both Client as Server have recursive references to each other. The magic of a weak reference will overcome this issue.
In the past, we would have demanded the user to call some server.close() function, but as we (java|type)script developers are lazy and not used with dealing with the garbage collector, we often forget.
With WeakRef the following happen
test(), reference all references to the client (clientA, clientB) get marked as deletable. As the variables are the only ones that count. The weak ref set is not counted as a referenceClient instances get deletedtest()'s server variable is gone, and so are all Client objects are gonetest() is fully and automatically cleaned upWhat happens with a typical Set?
test(), references to the clientA and clientB are still holden in the Server instance.FAQs
WeakRefSet, a weak set with access to the fields
The npm package weakrefset receives a total of 0 weekly downloads. As such, weakrefset popularity was classified as not popular.
We found that weakrefset demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.