Skip to content

Edge-Drop is a clipboard shelf on the edge of your screen. Hover to open it. Drag files and images into any app, click to copy text and links. Free and open-source for Windows.

perf(memory): explicitly dereference image PNG buffers and nativeImage handles after disk staging

Deepender2535968644ab13
diff --git a/electron/main/ipc.ts b/electron/main/ipc.ts
index e9c96b7..7548421 100644
--- a/electron/main/ipc.ts
+++ b/electron/main/ipc.ts
@@ -465,7 +465,7 @@ export function registerIpc(): void {
}
}
if (!img.isEmpty()) {
- const png = img.toPNG()
+ let png: Buffer | null = img.toPNG()
const size = img.getSize()
data.imageId = createId()
data.bytes = png.length
@@ -473,6 +473,8 @@ export function registerIpc(): void {
data.height = size.height
data.ext = 'png'
getStore().stageImageBytes(data.imageId, png)
+ png = null
+ img = null as any
}
} catch (err) {
console.error('[IPC] Failed to process dropped web image URL:', err)
diff --git a/electron/main/state.ts b/electron/main/state.ts
index 99cfbb9..d4c8940 100644
--- a/electron/main/state.ts
+++ b/electron/main/state.ts
@@ -56,6 +56,7 @@ export function initState(): void {
store.pruneExpired(loadSettings().autoDeleteHours)
if (data.kind === 'image' && png && data.imageId) {
store.stageImageBytes(data.imageId, png)
+ png = undefined as any
}
if (data.kind === 'files' && data.paths) {
prefetchFileIcons(data.paths)
diff --git a/electron/store/ItemStore.ts b/electron/store/ItemStore.ts
index a7f1096..2f95a04 100644
--- a/electron/store/ItemStore.ts
+++ b/electron/store/ItemStore.ts
@@ -481,13 +481,15 @@ export class ItemStore {
return cached
}
try {
- const img = nativeImage.createFromPath(this.imagePath(imageId, ext))
+ let img: any = nativeImage.createFromPath(this.imagePath(imageId, ext))
if (img.isEmpty()) return null
const size = img.getSize()
- const thumb = size.width > THUMB_SIZE || size.height > THUMB_SIZE
+ let thumb: any = size.width > THUMB_SIZE || size.height > THUMB_SIZE
? img.resize({ width: THUMB_SIZE, quality: 'good' })
: img
const url = thumb.toDataURL({ scaleFactor: 1 })
+ img = null
+ thumb = null
if (this.previewCache.size >= PREVIEW_CACHE_MAX) {
this.previewCache.delete(this.previewCache.keys().next().value!)
}