Skip to content

Conversation

@Boshen
Copy link
Member

@Boshen Boshen commented Sep 26, 2025

may fix #6121

The js side should not own the Arc.

@Boshen Boshen requested a review from Brooooooklyn September 26, 2025 17:29
@graphite-app
Copy link
Contributor

graphite-app bot commented Sep 26, 2025

How to use the Graphite Merge Queue

Add the label graphite: merge to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@netlify
Copy link

netlify bot commented Sep 26, 2025

Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit 9621383
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/68d6cd827739190008b2e353

}

fn inner(&self) -> Arc<OutputAsset> {
self.inner.upgrade().unwrap()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of crashing, the js side can set the value to undefined, or we throw a panic message "Rolldown has been shutdown, access to this data is no longer possible".

pub(crate) cache: ScanStageCache,
pub(crate) session: rolldown_debug::Session,
pub(crate) build_count: u32,
pub(crate) assets: Vec<Output>,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bundler needs to own the Arcs from Output.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not oppose this direction, but would it casue error if the bundler/assets get dropped and user try to access the assets?

This brings up a convention that if users wants to access the asset, they shouldn't make the the js object Bundler get GCed, which is hard thing to tell in the js world due to js doesn't have ownership concept.

Copy link
Member Author

@Boshen Boshen Sep 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, for script usages, use after free will not be allowed. i.e. it will crash when accessing asset data after rolldown has been closed.


self.assets.clear();
self.cache = ScanStageCache::default();
self.file_emitter.clear();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to clear everything stored in Bundler instead of relying on Drop.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this improvement could be appied first. No negative point found.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had applied this one in #6483.

}

let mut output = bundle_output?;
self.assets.extend(output.assets.iter().map(Clone::clone));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line might get triggered many times due to incremental build.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something else should own the assets, I stored them in bundler to prove my hypothesis.

@hyf0 hyf0 requested a review from IWANABETHATGUY September 26, 2025 18:51
@Boshen Boshen closed this Oct 27, 2025
@Boshen Boshen deleted the 09-26-fix_rolldown_binding_use_weak_outputchunk_to_prevent_memory_leak branch October 27, 2025 05:38
graphite-app bot pushed a commit that referenced this pull request Oct 27, 2025
…emory immediately (#6721)

This PR consolidates #6707 and #6696. Part of #6346.

```typescript
import { freeExternalMemory } from 'rolldown/experimental';

const bundle = await build.generate();

freeExternalMemory(bundle)

bundle.output // error
```

```typescript
import { freeExternalMemory } from 'rolldown/experimental';

const bundle = await build.generate();

freeExternalMemory(bundle, /*keepDataAlive:*/ true)

bundle.output // no error
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Memory is not released promptly with API usage

3 participants