Would you not have memory leak issues defining the user model multiple times in sequelize?
jay
1

jay What makes you believe that there is a memory leak? Each object is created per request and should be GCed after the request is complete.

I ran the code via node-inspector with apache-benchmark to see the problem of memory leak and did not find any issue. Below is the snapshot of the GC from the start and then from the end. Things look ok to me.

[27998:0x102803c00] 121462 ms: Mark-sweep 409.6 (461.6) -> 135.7 (378.6) MB, 90.3 / 0 ms [HeapObjectsMap::UpdateHeapObjectsMap] [GC in old space requested].
[27998:0x102803c00] 121725 ms: Mark-sweep 137.7 (378.6) -> 135.6 (195.6) MB, 121.0 / 0 ms [HeapObjectsMap::UpdateHeapObjectsMap] [GC in old space requested].
[27998:0x102803c00] 123346 ms: Mark-sweep 167.6 (220.6) -> 146.1 (218.6) MB, 86.0 / 0 ms [HeapObjectsMap::UpdateHeapObjectsMap] [GC in old space requested].
[27998:0x102803c00] 125797 ms: Mark-sweep 193.6 (248.6) -> 165.4 (246.6) MB, 96.6 / 0 ms [HeapObjectsMap::UpdateHeapObjectsMap] [GC in old space requested].
[27998:0x102803c00] 126165 ms: Mark-sweep 168.9 (246.6) -> 165.4 (223.6) MB, 108.0 / 0 ms [HeapObjectsMap::UpdateHeapObjectsMap] [GC in old space requested].
..
..
..
[27998:0x102803c00] 2219625 ms: Mark-sweep 116.1 (165.6) -> 81.7 (154.6) MB, 61.9 / 0 ms [HeapObjectsMap::UpdateHeapObjectsMap] [GC in old space requested].
[27998:0x102803c00] 2222878 ms: Mark-sweep 145.7 (181.6) -> 88.1 (167.6) MB, 68.1 / 0 ms [HeapObjectsMap::UpdateHeapObjectsMap] [GC in old space requested].
[27998:0x102803c00] 2223750 ms: Mark-sweep 110.3 (167.6) -> 89.4 (149.6) MB, 72.2 / 0 ms [HeapObjectsMap::UpdateHeapObjectsMap] [GC in old space requested].
[27998:0x102803c00] 2224636 ms: Mark-sweep 112.1 (151.6) -> 90.7 (151.6) MB, 66.6 / 0 ms [HeapObjectsMap::UpdateHeapObjectsMap] [GC in old space requested].
[27998:0x102803c00] 2224963 ms: Mark-sweep 99.4 (151.6) -> 90.7 (144.6) MB, 66.8 / 0 ms [HeapObjectsMap::UpdateHeapObjectsMap] [GC in old space requested].
[27998:0x102803c00] 2225242 ms: Mark-sweep 99.6 (144.6) -> 64.1 (142.6) MB, 48.5 / 0 ms [HeapObjectsMap::UpdateHeapObjectsMap] [GC in old space requested].
[27998:0x102803c00] 2225510 ms: Mark-sweep 68.3 (142.6) -> 58.0 (114.6) MB, 53.5 / 0 ms [HeapObjectsMap::UpdateHeapObjectsMap] [GC in old space requested].
[27998:0x102803c00] 2225744 ms: Mark-sweep 59.7 (114.6) -> 58.0 (109.6) MB, 47.3 / 0 ms [HeapObjectsMap::UpdateHeapObjectsMap] [GC in old space requested].
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.