Skip to content

Instantly share code, notes, and snippets.

@oalfroukh
Created October 12, 2022 13:33
Show Gist options
  • Save oalfroukh/da9a7958c4f989ff3ef7d9941e00c066 to your computer and use it in GitHub Desktop.
Save oalfroukh/da9a7958c4f989ff3ef7d9941e00c066 to your computer and use it in GitHub Desktop.
loadMemory
<!DOCTYPE html>
<html>
<body>
<div id="container">
</div>
<script>
const container = document.getElementById("container");
const arrays = [];
let count = 0;
const idleCallback = () =>{
console.log("idleCallback");
container.innerHTML = count++;
try {
const a = new Uint8Array(1000*1024*1024)
a.fill(12)
arrays.push(a)
window.requestIdleCallback(idleCallback)
} catch (error) {
console.error("errr",error)
container.innerHTML = `${arrays.reduce((acc, cur)=> acc + cur.byteLength, 0)/1024/1024/1024} GB at ${--count}`
}
}
window.requestIdleCallback(idleCallback)
const arrays1 = [];
// while (true){
setInterval( () => {
console.log("while");
const a = new Uint8Array(1000*1024*1024)
a.fill(12)
arrays1.push(a)
console.log(`${arrays1.reduce((acc, cur)=> acc + cur.byteLength, 0)/1024/1024/1024} GB`);
},10);
// }
</script>
</body>
</html>
// Modules to control application life and create native browser window
const {app, BrowserWindow} = require('electron')
const path = require('path')
function createWindow () {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
sandbox:false,
contextIsolation: true,
nodeIntegration: false,
preload: path.join(__dirname, 'preload.js')
}
})
// and load the index.html of the app.
mainWindow.loadFile('index.html')
// Open the DevTools.
mainWindow.webContents.openDevTools({ mode: "undocked", activate: true });
}
// app.commandLine.appendSwitch("disable-gpu");
// app.commandLine.appendSwitch("in-process-gpu");
// app.commandLine.appendSwitch("disable-software-rasterizer");
app.commandLine.appendSwitch("no-sandbox");
// app.commandLine.appendSwitch("disable-gpu-sandbox");
// app.commandLine.appendSwitch('js-flags', '--max-old-space-size=3596');
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
createWindow()
app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow()
});
});
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
{
"name": "loadMemory",
"productName": "loadMemory",
"description": "My Electron application description",
"keywords": [],
"main": "./main.js",
"version": "1.0.0",
"author": "oalfroukh",
"scripts": {
"start": "electron ."
},
"dependencies": {},
"devDependencies": {
"electron": "19.1.2"
}
}
// All of the Node.js APIs are available in the preload process.
// It has the same sandbox as a Chrome extension.
window.addEventListener('DOMContentLoaded', () => {
const replaceText = (selector, text) => {
const element = document.getElementById(selector)
if (element) element.innerText = text
}
for (const type of ['chrome', 'node', 'electron']) {
replaceText(`${type}-version`, process.versions[type])
}
})
setInterval( () => {
console.info(`Memory usage by ${process.memoryUsage().rss / 1000000}MB`);
},3000);
// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// No Node.js APIs are available in this process because
// `nodeIntegration` is turned off. Use `preload.js` to
// selectively enable features needed in the rendering
// process.
/* styles.css */
/* Add styles here to customize the appearance of your app */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment