Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/components/sidebar/tabs/queue/TaskItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ onMounted(() => {
})

onUnmounted(() => {
if (progressPreviewBlobUrl.value) {
URL.revokeObjectURL(progressPreviewBlobUrl.value)
}
api.removeEventListener('b_preview', onProgressPreviewReceived)
})

Expand Down Expand Up @@ -164,6 +167,9 @@ const formatTime = (time?: number) => {

const onProgressPreviewReceived = async ({ detail }: CustomEvent) => {
if (props.task.displayStatus === TaskItemDisplayStatus.Running) {
if (progressPreviewBlobUrl.value) {
URL.revokeObjectURL(progressPreviewBlobUrl.value)
}
progressPreviewBlobUrl.value = URL.createObjectURL(detail)
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/scripts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,7 @@ export class ComfyApp {
api.addEventListener('executing', ({ detail }) => {
this.progress = null
this.graph.setDirtyCanvas(true, false)
this.revokePreviews(this.runningNodeId)
delete this.nodePreviewImages[this.runningNodeId]
})

Expand Down Expand Up @@ -1589,6 +1590,8 @@ export class ComfyApp {

const blob = detail
const blobUrl = URL.createObjectURL(blob)
// Ensure clean up if `executing` event is missed.
this.revokePreviews(id)
this.nodePreviewImages[id] = [blobUrl]
})

Expand Down Expand Up @@ -2835,11 +2838,24 @@ export class ComfyApp {
app.graph.setDirtyCanvas(true, true)
}

/**
* Frees memory allocated to image preview blobs for a specific node, by revoking the URLs associated with them.
* @param nodeId ID of the node to revoke all preview images of
*/
revokePreviews(nodeId: NodeId) {
if (!this.nodePreviewImages[nodeId]?.[Symbol.iterator]) return
for (const url of this.nodePreviewImages[nodeId]) {
URL.revokeObjectURL(url)
}
}
/**
* Clean current state
*/
clean() {
this.nodeOutputs = {}
for (const id of Object.keys(this.nodePreviewImages)) {
this.revokePreviews(id)
}
this.nodePreviewImages = {}
this.lastNodeErrors = null
this.lastExecutionError = null
Expand Down
Loading