-
-
Save FrostBird347/90dd48c54fdde69a00ab641b1ee823f2 to your computer and use it in GitHub Desktop.
/** | |
* @name PurgeMemory | |
* @authorLink https://github.com/FrostBird347 | |
* @source https://gist.github.com/FrostBird347/90dd48c54fdde69a00ab641b1ee823f2#gistcomment-4388425 | |
* @updateUrl https://gist.githubusercontent.com/FrostBird347/90dd48c54fdde69a00ab641b1ee823f2/raw/PurgeMemory.plugin.js | |
*/ | |
module.exports = class PurgeMemory { | |
getName () {return "PurgeMemory";} | |
getDescription () {return "Attempts to flush discord's memory. Doesn't always work well enough, but I have observed best results when used multiple times.";} | |
getVersion() {return "1.1.4";} | |
getAuthor () {return "FrostBird347";} | |
load() {} | |
stop() { | |
clearInterval(this.buttonCheckID); | |
clearInterval(this.buttonUpdateID); | |
try { | |
this.PurgeMemoryButton.remove(); | |
} catch {} | |
} | |
start() { | |
//Simple update notifier | |
//I have been unable to figure out how to obtain the plugin's version | |
let CurrentVersion = "1.1.4" | |
window.fetch("https://gist.githubusercontent.com/FrostBird347/90dd48c54fdde69a00ab641b1ee823f2/raw/PurgeMemory.plugin.js").then(function(response) { | |
response.text().then(function(text) { | |
let Lines = text.split("\t").join("").split("\n") | |
let RemoteVersion = "" | |
for (var l = 0; l < Lines.length; l++) { | |
if (RemoteVersion == "" && Lines[l].split(" ").join("").split("\"")[0] == "getVersion(){return") { | |
RemoteVersion = Lines[l].split(" ").join("").split("\"")[1] | |
} | |
} | |
if (RemoteVersion != CurrentVersion) { | |
window.BdApi.UI.showToast("PurgeMemory is outdated!\nCurrent: " + CurrentVersion + "\nLatest: " + RemoteVersion, {type: "info", icon:true, timeout: 7500}) | |
} | |
}) | |
}) | |
this.ElementClasses = { | |
"Toolbar": "toolbar__62fb5", | |
"IconWrapper": "iconWrapper_de6cd1", | |
"Clickable": "clickable_ce0925", | |
"Icon": "icon_ae0b42" | |
} | |
this.buttonCheckID = setInterval(this.buttonCheck, 5000, this); | |
this.buttonUpdateID = setInterval(this.buttonUpdate, 2500, this); | |
} | |
buttonCheck(Plugin) { | |
let ToolbarElement = document.getElementsByClassName(Plugin.ElementClasses.Toolbar)[0]; | |
if (ToolbarElement != undefined && ToolbarElement.getElementsByClassName("PurgeMemoryButton").length == 0) { | |
Plugin.PurgeMemoryButton = document.createElement("div"); | |
Plugin.PurgeMemoryButton.className = "PurgeMemoryButton " + Plugin.ElementClasses.IconWrapper + " " + Plugin.ElementClasses.Clickable; | |
Plugin.PurgeMemoryButton.attributes.role = "Button"; | |
Plugin.PurgeMemoryButton.ariaLabel = "Inbox"; | |
Plugin.PurgeMemoryButton.ariaExpanded = false; | |
Plugin.PurgeMemoryButton.tabIndex = 0; | |
Plugin.PurgeMemoryButton.innerHTML = '<svg x="0" y="0" class="' + Plugin.ElementClasses.Icon + '" aria-hidden="true" role="img" width="24" height="24" viewBox="0 0 24 24" fill="none"><path d="M15 3.999V2H9V3.999H3V5.999H21V3.999H15Z" fill="currentColor"></path><path d="M5 6.99902V18.999C5 20.101 5.897 20.999 7 20.999H17C18.103 20.999 19 20.101 19 18.999V6.99902H5ZM11 17H9V11H11V17ZM15 17H13V11H15V17Z" fill="currentColor"></path></svg>'; | |
ToolbarElement.prepend(Plugin.PurgeMemoryButton); | |
Plugin.PurgeMemoryTooltip = BdApi.UI.createTooltip(Plugin.PurgeMemoryButton, "Purge Memory", { style: "primary" }); | |
Plugin.PurgeMemoryButton.addEventListener('click', function(event) { | |
Plugin.PurgeMemoryButton.children[0].style.color = "var(--brand-experiment)"; | |
Plugin.PurgeMemoryButton.style.pointerEvents = "none"; | |
for (let i = 0; i < 8; i++) { | |
setTimeout(function() { | |
DiscordNative.processUtils.purgeMemory(); | |
console.log("PurgeMemory triggered"); | |
}, i * 625) | |
} | |
setTimeout(function() { | |
Plugin.PurgeMemoryButton.children[0].style.color = ""; | |
Plugin.PurgeMemoryButton.style.pointerEvents = ""; | |
}, 5000) | |
}, false) | |
} | |
} | |
buttonUpdate(Plugin) { | |
if (Plugin.PurgeMemoryButton != undefined && Plugin.PurgeMemoryTooltip != undefined) { | |
require('process').getProcessMemoryInfo().then(function(Memory) { | |
Plugin.PurgeMemoryTooltip.label = "Purge Memory (" + Math.round(Memory.private / 1000) + "MB)" | |
}) | |
} | |
} | |
} |
the PurgeMemory button does nothing when i click on it
When clicked the button runs the function DiscordNative.processUtils.purgeMemory()
a few times and prints a log in the console.
I have updated the plugin to give a visual indicator that the users input has been received.
The purge function itself does not immediately cause the ram usage to go down and seems to work better when pressed multiple times.
In addition to this, the tooltip text is only updated once every 2.5 seconds and must be hovered over again before the updated text will be displayed.
you should use https://openasar.dev/ and https://github.com/clachoverclan/DiscordRamLimit to have discord use the least amount of resources
you should use https://openasar.dev/ and https://github.com/clachoverclan/DiscordRamLimit to have discord use the least amount of resources
Unfortunately, the ram limit program is not an option for users on operating systems other than windows and OpenAsar, while improving performance doesn't fix whatever memory leak my client has.
For anybody else in the future reading this, I strongly recommend auditing/verifying the validity of both programs and coming to your own conclusion on whether continued use of said programs (especially OpenAsar, which auto updates) are a worthwhile risk before using them.
the PurgeMemory button does nothing when i click on it