| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/WebAssembly/Reference/Data/drop | [Back] [Original] |
Get to know MDN better
The data.drop data instruction discards the data contained by a passive data definition, freeing up its memory, after being used in a memory.init.
Note:
Active data segments are dropped automatically during module instantiation, and therefore are not available to drop via data.drop.
(module
(memory (export "memory") 1)
(data $greeting "Hello")
(func (export "init")
i32.const 0 ;; destination offset in memory
i32.const 0 ;; offset into the data segment
i32.const 5 ;; number of bytes to copy
memory.init $greeting
data.drop $greeting
)
)
WebAssembly.instantiateStreaming(fetch("{%wasm-url%}")).then((result) => {
result.instance.exports.init();
const memBuffer = result.instance.exports.memory.buffer;
const memArray = new Uint8Array(memBuffer, 0, 5);
console.log(new TextDecoder().decode(memArray));
});
In the above example, we define a memory and a data called $greeting that contains the string Hello. We then invoke memory.init to copy the string over to the memory. With this done, the data is no longer needed, so we call data.drop to free up the memory it was using.
data.drop identifier
data.dropThe data.drop instruction type. Must always be included first.
identifierThe identifier for the data you want to drop. This can be one of the following:
nameAn identifying name set for the data when it was first defined. This must begin with a $ symbol, for example $my_data.
indexThe data's index number, for example 0 for the first data in the wasm module, 1 for the second, etc.
[] -> []
| Instruction | Binary format | Example text => binary |
|---|---|---|
data.drop |
0xfc 9:u32 x:dataidx |
data.drop 0 => 0xfc 0x09 0x00 |
| Specification |
|---|
| WebAssembly Core Specification # -hrefsyntax-instr-memorymathsfdatadropx%E2%91%A0 |
memory definitiondata definitionThis page was last modified on Aug 2, 2026 by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |