I am writing a script with interface that creates a comps contain text and shape layers. I have been testing the script by creating one comp every time I testing it as I am writing the code and everything was normal until I accidentally tried to create multiple comps then it crashed. I check everything but it keeps crashing whenever i create more than one comp.
I am using Git so I backed couple versions and I found that the problem started occur when I started splitting the code to multiple libraries to keep it maintainable because its fairly long and contains many functions and modules, so I am wandering if there are any limitations to the number of libraries or variables or loops that I can use in AE script. And also if there is a way to debug the crash and understand what's going on. I am using Atom on Mac and not showing anything.

I have been learning and writing script for few months now.. so I will be very grateful for any advice.

Update..
I tried to test the script on Windows and it's same problem but the difference is showing legitimate message which says:
"After Effects: Memory allocation of 12.3 GB exceeds internal limits. Decrease the memory requirements for the rendering of this frame. (12802). For more information, see www.adobe.com/fo/lear_ae_mem"

It sounds a memory problem so maybe something wrong with variables scope or the loops i'm using? I have few global vars waiting util I finish to put them inside a main function but could they causing this problem?

Thanks Runegan for your response!
I am using #include and I don't think the comp resolution or duration is the problem. I ran many tests and I think the problem occur in the objects that I am passing by the function arguments. I am not sure but I think they're kind of not releasing the memory after the function is done and keep staking the data(not sure just personal thought). So I did some research about the memory management in JavaScript and I'm reading about memory leak and how to avoid it but still not sure if I need to clear this objects manually every time I use them?

briefly my script is a UI that generated by long "resourceString" and by onClick button it passes couple of objects as arguments to multiple functions to create the comp. these objects are a parameters that have been collected from the UI. the script creates first and second comp normally but crashes the AE on the third comp. sometimes ExtendScript showes the object is "undefined" before it crashes.

the problem finally solved and I would like to share what it was.
After I inspected every single function in the script I was suspicious about one function that creates the GUI. I used Mathias Möhl approach but it contains some statements I wasn't sure if they were necessary to have. I tried to search about it and I liked David Torno approach of how he build the GUI in AE. So I used it after a little tweaks and the problem solved.