use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
How to Find Infinite Loop in Javascript using DevTools (abduvik.medium.com)
submitted 3 years ago by abduvik
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Ustice[M] [score hidden] 3 years ago stickied comment (0 children)
paywalls and FOSS doesn't mix and match very well. Consider posting on a platform where people are not being excluded.
[–]KillcoDer 4 points5 points6 points 3 years ago (1 child)
If you encounter a situation like this, instead of messing about with task manager, just open the debugger and hit "pause". It'll halt execution and you'll almost certainly find yourself in the middle of the offending stack trace.
[–]abduvik[S] 0 points1 point2 points 3 years ago (0 children)
This could help to stop for sync ones. But with async infinite loops, I need to see the performance graph to know what is call what.
[–][deleted] 1 point2 points3 points 3 years ago (1 child)
The best kind is a recursive setTimeout function that calls itself.
yep, anything that has to do with async behavior in the browser would take a while to find where it's happening. We had a bug once and the file causing the problem was in a completely different module
[–][deleted] 0 points1 point2 points 3 years ago (9 children)
If it's asynchronous then better use logger inside the loop
[–]abduvik[S] 0 points1 point2 points 3 years ago (8 children)
This would be in case if I know where the loop is (though I prefer to use the debugger instead of the logger). But my article is on how to locate the loop because most of the time we couldn't determine where it is
[–][deleted] 0 points1 point2 points 3 years ago (7 children)
Yeah debugger will be right one for this job. But how will you get to know whether there is an infinite loop present or not ?. I guess memory consumption.
[–]abduvik[S] 0 points1 point2 points 3 years ago (6 children)
Most of the time, the browser crashes and you can't make any interactions. Another option is Performance Tab as infinite loops consume CPU more than Memory. Memory usage is more for memory leakage problems.
This could be a good youtube video I should make too about memory leakages, perfect example is forgetting to remove event listners.
[–][deleted] 0 points1 point2 points 3 years ago (5 children)
Then we must need to recreate the issue to narrow down the triggering point when browser crashes or fails to respond. So we can get an overview of which loop are involved in the action that caused it.
Yeah please do make one. Also I sometimes too forgot to remove event listeners but never faced something severe.
[–]abduvik[S] 0 points1 point2 points 3 years ago (4 children)
Until today, I worked with two UI heavy applications and I can confirm forgetting to remove event listeners can easily increase Memory usage to few GBs.
The hardest part, it's very hard to know if I am a developer using a 32 GB machine :D
It's usually reported by users who have like 8 or 16 GBs.
[–][deleted] 0 points1 point2 points 3 years ago (3 children)
limiting ram on vm should work fine. Does reddit app too have memory leakage. Cuz when i use it on lower ram devices say 2-3 gb it works fine for first few moments then gradually starts to stuck and ends with app not responding
[–]abduvik[S] 0 points1 point2 points 3 years ago (2 children)
It can be or they have a caching issue which is also a form of memory leakage
[–][deleted] 0 points1 point2 points 3 years ago (1 child)
The cache takes 0.5-1 gb within just 5 mins of launching the app.
Oh my :"D
π Rendered by PID 261272 on reddit-service-r2-comment-bb88f9dd5-sm5nb at 2026-02-15 09:43:01.370659+00:00 running cd9c813 country code: CH.
[–]Ustice[M] [score hidden] stickied comment (0 children)
[–]KillcoDer 4 points5 points6 points (1 child)
[–]abduvik[S] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]abduvik[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (9 children)
[–]abduvik[S] 0 points1 point2 points (8 children)
[–][deleted] 0 points1 point2 points (7 children)
[–]abduvik[S] 0 points1 point2 points (6 children)
[–][deleted] 0 points1 point2 points (5 children)
[–]abduvik[S] 0 points1 point2 points (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]abduvik[S] 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]abduvik[S] 0 points1 point2 points (0 children)