在 Angular 8 SSR 应用程序中,存在内存泄漏
我有一个有角度的 SSR 应用程序,它会导致服务器上的内存泄漏
,当许多用户使用并打开该应用程序时,它会不断增加服务器上的内存。在 ngOnDestroy 上取消订阅不起作用,内存泄漏仍然存在
无法找到什么问题以及解决问题的正确方法是什么
我附加了 server.ts 代码
import "zone.js/dist/zone-node";
import * as express from "express";
import { join } from "path";
const domino = require("domino");
const fs = require("fs");
const path = require("path");
const app = express();
const PORT = process.env.PORT || 4000;
const DIST_FOLDER = join(process.cwd(), "dist/browser");
const template = fs
.readFileSync(path.join(DIST_FOLDER, "index.html"))
.toString();
const win = domino.createWindow(template);
(global as any)["window"] = win;
(global as any)["KeyboardEvent"] = win.KeyboardEvent;
(global as any)["HTMLInputElement"] = win.HTMLInputElement;
(global as any)["MouseEvent"] = win.MouseEvent;
(global as any)["Event"] = win.Event;
(global as any)["document"] = win.document;
(global as any)["navigator"] = win.navigator;
(global as any)["FormData"] = win.FormData;
// * NOTE :: leave this as require() since this file is built Dynamically from webpack
const {
AppServerModuleNgFactory,
LAZY_MODULE_MAP,
ngExpressEngine,
provideModuleMap,
} = require("./dist/server/main");
app.engine(
"html",
ngExpressEngine({
bootstrap: AppServerModuleNgFactory,
providers: [provideModuleMap(LAZY_MODULE_MAP)],
})
);
app.set("view engine", "html");
app.set("views", DIST_FOLDER);
app.get(
"*.*",
express.static(DIST_FOLDER, {
maxAge: "1y",
})
);
app.get(/.*aspx$/, function (req, res) {
res.redirect(301, "WEBSITE URL");
});
// All regular routes use the Universal engine
app.get("*", (req, res, next) => {
// special for robots.txt
if (req.url === "/robots.txt") {
next();
return;
}
res.render("index", { req });
});
app.listen(PORT, () => {
console.log(`Node Express server listening on http://localhost:${PORT}`);
});
I have an angular SSR app that causes memory leaks on the server
it keeps on increasing memory on the server when the application is used and opened by many users.Unsubscribing subscriptions on ngOnDestroy doesn't work, still memory leaks persist
Not able to find whats the issue and whats the correct way to solve the problem
I am attaching the server.ts code
import "zone.js/dist/zone-node";
import * as express from "express";
import { join } from "path";
const domino = require("domino");
const fs = require("fs");
const path = require("path");
const app = express();
const PORT = process.env.PORT || 4000;
const DIST_FOLDER = join(process.cwd(), "dist/browser");
const template = fs
.readFileSync(path.join(DIST_FOLDER, "index.html"))
.toString();
const win = domino.createWindow(template);
(global as any)["window"] = win;
(global as any)["KeyboardEvent"] = win.KeyboardEvent;
(global as any)["HTMLInputElement"] = win.HTMLInputElement;
(global as any)["MouseEvent"] = win.MouseEvent;
(global as any)["Event"] = win.Event;
(global as any)["document"] = win.document;
(global as any)["navigator"] = win.navigator;
(global as any)["FormData"] = win.FormData;
// * NOTE :: leave this as require() since this file is built Dynamically from webpack
const {
AppServerModuleNgFactory,
LAZY_MODULE_MAP,
ngExpressEngine,
provideModuleMap,
} = require("./dist/server/main");
app.engine(
"html",
ngExpressEngine({
bootstrap: AppServerModuleNgFactory,
providers: [provideModuleMap(LAZY_MODULE_MAP)],
})
);
app.set("view engine", "html");
app.set("views", DIST_FOLDER);
app.get(
"*.*",
express.static(DIST_FOLDER, {
maxAge: "1y",
})
);
app.get(/.*aspx$/, function (req, res) {
res.redirect(301, "WEBSITE URL");
});
// All regular routes use the Universal engine
app.get("*", (req, res, next) => {
// special for robots.txt
if (req.url === "/robots.txt") {
next();
return;
}
res.render("index", { req });
});
app.listen(PORT, () => {
console.log(`Node Express server listening on http://localhost:${PORT}`);
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论