ngx-device-detector icon indicating copy to clipboard operation
ngx-device-detector copied to clipboard

Memory leak and performance

Open KamilPuczka opened this issue 4 years ago • 3 comments

Hi,

I found issue with your library. It causes memory leaks. https://github.com/KoderLabs/ngx-device-detector/blob/master/projects/ngx-device-detector/src/lib/device-detector.constants.ts here you create regex objects. Those objects cannot be handled by garbage collector. Regex should be created if needed and destroy after check. Keep them like that make them unavailable for garbage collector.

Furthermore, why don't you cache result of checking? Each time I call isMobile/Tablet/Desktop regexes are checked. In my opinion it should be checked on first method call, then result should be kept in memory. User Agent won't change so checking each time is redundant.

KamilPuczka avatar Dec 03 '20 15:12 KamilPuczka

@KamilPuczka good points. Will get on it.

AhsanAyaz avatar Jan 26 '21 04:01 AhsanAyaz

hi, first thank you for your cooperation for this lib, but need know if update lib with respect in the question old.

avargas26 avatar Mar 02 '21 12:03 avargas26

Any updates on this?

rvalitov avatar Oct 26 '21 20:10 rvalitov