AhsanAyaz / AhsanAyaz/ngx-device-detector

Memory leak and performance

Open
#187 3 comments 1 reaction 1 assignee Assigned to @mohsinayaz View on GitHub
enhancement
Dominant language
TypeScript
Stars
560
Forks
106
PR merge metrics
No merged PRs in 30d

Description

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](url) 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.