Results 1 to 28 of 28

Thread: My app just takes up more and more ram as time goes on

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269

    My app just takes up more and more ram as time goes on

    Reaching 5-600 mb in 3 hours
    Its a chat server that has ~5000 users chatting on it in 3 hours
    but the ram just goes higher and higher

    i have no idea why, ive checked the code its tight as can be..
    any suggestions?

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: My app just takes up more and more ram as time goes on

    Quote Originally Posted by VaxoP
    ...ive checked the code its tight as can be...
    Unfortunately if that were true you wouldn't have a memory leak. Do you explicitly set all objects to Nothing when you are done with them?

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269

    Re: My app just takes up more and more ram as time goes on

    Quote Originally Posted by MartinLiss
    Unfortunately if that were true you wouldn't have a memory leak. Do you explicitly set all objects to Nothing when you are done with them?
    even strings/variables?

  4. #4

  5. #5
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: My app just takes up more and more ram as time goes on

    Quote Originally Posted by VaxoP
    even strings/variables?
    YES, YES and YES - if you don't need any of it then erase. Use local vars as much as you possible can. Use byte arrays in oppose to variants or strings if you can. Make sure you do explicitly declare string vars and not variants. Remomber that Dim abc, def, ghi As String will result in only GHI to be string variable and rest to be variants. And so on ... "Tight code" doesn't really mean much.

  6. #6
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: My app just takes up more and more ram as time goes on

    Quote Originally Posted by RhinoBull
    YES, YES and YES - if you don't need any of it then erase. Use local vars as much as you possible can. Use byte arrays in oppose to variants or strings if you can. Make sure you do explicitly declare string vars and not variants. Remomber that Dim abc, def, ghi As String will result in only GHI to be string variable and rest to be variants. And so on ... "Tight code" doesn't really mean much.
    While much of what you say are good practices, as long as you unload your forms and set them to Nothing, I don't think that variables of any type could lead to increasing memory use.

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269

    Re: My app just takes up more and more ram as time goes on

    I just have one form
    and almost all my variables are local
    dont those variables get destroyed once the sub is finished?

  8. #8
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: My app just takes up more and more ram as time goes on

    If you log a buffer or keep track of users who have disconnected (ie. whowas like on IRC), then make sure you erase old info every now and then.

  9. #9
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    537

    Re: My app just takes up more and more ram as time goes on

    If you have a timer on your form, would it be better to declare your variables locally, or globally?

    -Sir Loin

  10. #10
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: My app just takes up more and more ram as time goes on

    Quote Originally Posted by VaxoP
    I just have one form
    and almost all my variables are local
    dont those variables get destroyed once the sub is finished?
    Form level variables are maintained until the form is set to Nothing. Hoe are you handling the form. Open once and never close?

  11. #11
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: My app just takes up more and more ram as time goes on

    Quote Originally Posted by MartinLiss
    While much of what you say are good practices, as long as you unload your forms and set them to Nothing, I don't think that variables of any type could lead to increasing memory use.
    Not always, Martin - static variables (especially object type) will remain in memory until you reset them which is one of the drawbacks of using them.

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269

    Re: My app just takes up more and more ram as time goes on

    Quote Originally Posted by MartinLiss
    Form level variables are maintained until the form is set to Nothing. Hoe are you handling the form. Open once and never close?
    yep

  13. #13
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: My app just takes up more and more ram as time goes on

    If you set your swap drive size to very small, wouldn't the app crash rather quickly (depending on your amount of RAM?)

  14. #14

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269

    Re: My app just takes up more and more ram as time goes on

    Quote Originally Posted by dglienna
    If you set your swap drive size to very small, wouldn't the app crash rather quickly (depending on your amount of RAM?)
    occasionally my app just closes for no reason..

  15. #15

  16. #16
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: My app just takes up more and more ram as time goes on

    Do you happen to use subclassing? Or do you use WinSock control or a custom class module for connections? Anyways, I think you should seriously debug and see which variables or arrays grow in size all the time.

  17. #17
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: My app just takes up more and more ram as time goes on

    In case you still can't find any bugs in your memory handling, take a look at this:
    Obtain a Malloc object and try using the HeapMinimize call.

    Minimizes the heap as much as possible by releasing unused memory to the operating system.
    Last edited by penagate; Aug 28th, 2005 at 02:08 AM.

  18. #18
    Fanatic Member BrianHawley's Avatar
    Join Date
    Aug 2001
    Location
    Saudi Arabia
    Posts
    796

    Re: My app just takes up more and more ram as time goes on

    Just another thought. Are you using any third-party tools, Active-x controls etc?

    Any commerically sold product should not have memory leaks, but it would not be the first time......
    Brian
    (Fighting with the RightToLeft bugs in VS 2005)

  19. #19
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: My app just takes up more and more ram as time goes on

    If its a chat server, with quite a bit of chat going on, wouldn't wherever the chat is (textbox/richtextbox) be using up alot of memory? Programs like mIRC delete certain bits of the oldest chat, which is why I assume this would be happening (after 3 hours or consistent chat).

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  20. #20
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: My app just takes up more and more ram as time goes on

    Check also if you have Service Pack 6 for Visual Basic, if you don't, install it right away !

    I had memory problems just like you, before Service Pack 6 came out...

  21. #21
    Fanatic Member
    Join Date
    Jan 2005
    Location
    In front of this pc.
    Posts
    580

    Re: My app just takes up more and more ram as time goes on

    If you are using the winsock control STOP doing that! It will cause the problem you are having, especially with extended use. There's some pretty good code around the board here for a pure socket replacment (maybe Rhino's code?) but if you have problems working with sockets perhaps this project will help you get those sorted out.

    Also, as suggested by Merri, insure that any strings you are using are cleared occasionally - if a string exceeds it's max length it will result in an "out of memory" error.

    If your program crashes without any error message being generated that suggest, to me anyway, either an an activex control hiccuping or, more likely, an API call which is experiencing an error. API calls have normally been the cuplrit when I've had programs die without any error message.

  22. #22
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: My app just takes up more and more ram as time goes on

    As you can see we can go on guessing what's wrong with your code until the cows come home and still don't give you the correct answer. It's impossible to debug a program which we haven't used or seen any code for. Is it the regular memory usage that increases or the VM size or perhaps the GDI objects? If the latter what kind of GDI APIs are you using? Are you using any other APIs from which you gain a handle of some sort and you never release?

  23. #23

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269

    Re: My app just takes up more and more ram as time goes on

    im not using any gdi objects
    i just upgraded to sp6 (but the problem persists)
    i AM using the winsock control
    i clear the textbox that contains the chat data every few mins
    i dont have many form level or public variables, most are just sub variables
    i have no 3rd party tools

  24. #24

  25. #25
    Fanatic Member BrianHawley's Avatar
    Join Date
    Aug 2001
    Location
    Saudi Arabia
    Posts
    796

    Re: My app just takes up more and more ram as time goes on

    I'd vote for the winsock as being the culprit.

    It used to be notorious for memory leaks - supposedly now fixed by MS, but who knows.
    Brian
    (Fighting with the RightToLeft bugs in VS 2005)

  26. #26
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: My app just takes up more and more ram as time goes on

    Are you using it from code or as a control. If it is from code then, when your memory usage is high, try destroying and reinstantiating the winsock class to see if that fixes your memory issue.

    If your not using it from code (or if you can't do that... can't remember) try one of the Winsock classes available, I think there are some in the Codebank or elsewhere on the internet.

  27. #27

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269

    Re: My app just takes up more and more ram as time goes on

    the thing is i have a array of like 700 winsocks.. can i do the same thing with a class?

  28. #28
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: My app just takes up more and more ram as time goes on

    Holy bonanza! *tv theme tune starts playing*

    That is for sure the reason you have troubles. You can do the same with a class, one class you could try is CSocketMaster from PSC.

    You could also take a look into Pure IRCd which is very efficient IRCd server implementation on VB6. You might find some good ideas in it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width