Web: force gc in server.js
This commit is contained in:
parent
699c5f7af4
commit
b449dcf655
|
@ -3,6 +3,7 @@ const path = require('path');
|
||||||
const yargs = require('yargs/yargs');
|
const yargs = require('yargs/yargs');
|
||||||
const { hideBin } = require('yargs/helpers');
|
const { hideBin } = require('yargs/helpers');
|
||||||
const koffi = require('koffi');
|
const koffi = require('koffi');
|
||||||
|
require('expose-gc');
|
||||||
|
|
||||||
// Parse command line arguments
|
// Parse command line arguments
|
||||||
const argv = yargs(hideBin(process.argv))
|
const argv = yargs(hideBin(process.argv))
|
||||||
|
@ -37,7 +38,7 @@ let nasalLib;
|
||||||
try {
|
try {
|
||||||
// First load the library
|
// First load the library
|
||||||
const lib = koffi.load(path.join(__dirname, '../module/libnasal-web.dylib'));
|
const lib = koffi.load(path.join(__dirname, '../module/libnasal-web.dylib'));
|
||||||
|
|
||||||
// Then declare the functions explicitly
|
// Then declare the functions explicitly
|
||||||
nasalLib = {
|
nasalLib = {
|
||||||
nasal_init: lib.func('nasal_init', 'void*', []),
|
nasal_init: lib.func('nasal_init', 'void*', []),
|
||||||
|
@ -45,7 +46,7 @@ try {
|
||||||
nasal_eval: lib.func('nasal_eval', 'const char*', ['void*', 'const char*', 'int']),
|
nasal_eval: lib.func('nasal_eval', 'const char*', ['void*', 'const char*', 'int']),
|
||||||
nasal_get_error: lib.func('nasal_get_error', 'const char*', ['void*'])
|
nasal_get_error: lib.func('nasal_get_error', 'const char*', ['void*'])
|
||||||
};
|
};
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to load nasal library:', err);
|
console.error('Failed to load nasal library:', err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
@ -66,7 +67,7 @@ app.post('/eval', (req, res) => {
|
||||||
try {
|
try {
|
||||||
const result = nasalLib.nasal_eval(ctx, code, showTime ? 1 : 0);
|
const result = nasalLib.nasal_eval(ctx, code, showTime ? 1 : 0);
|
||||||
const error = nasalLib.nasal_get_error(ctx);
|
const error = nasalLib.nasal_get_error(ctx);
|
||||||
|
|
||||||
if (error && error !== 'null') {
|
if (error && error !== 'null') {
|
||||||
if (argv.verbose) console.log('Nasal error:', error);
|
if (argv.verbose) console.log('Nasal error:', error);
|
||||||
res.json({ error: error });
|
res.json({ error: error });
|
||||||
|
@ -83,6 +84,7 @@ app.post('/eval', (req, res) => {
|
||||||
} finally {
|
} finally {
|
||||||
if (argv.verbose) console.log('Cleaning up Nasal context');
|
if (argv.verbose) console.log('Cleaning up Nasal context');
|
||||||
nasalLib.nasal_cleanup(ctx);
|
nasalLib.nasal_cleanup(ctx);
|
||||||
|
global.gc()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -91,4 +93,4 @@ app.listen(PORT, () => {
|
||||||
console.log(`Server running on port ${PORT}`);
|
console.log(`Server running on port ${PORT}`);
|
||||||
console.log(`Visit http://localhost:${PORT} to use the Nasal interpreter`);
|
console.log(`Visit http://localhost:${PORT} to use the Nasal interpreter`);
|
||||||
if (argv.verbose) console.log('Verbose logging enabled');
|
if (argv.verbose) console.log('Verbose logging enabled');
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue