Results 1 to 15 of 15

Thread: How To Free Memory from my app?

  1. #1

    Thread Starter
    Hyperactive Member eranfox's Avatar
    Join Date
    May 2001
    Posts
    492

    How To Free Memory from my app?

    Hello Everybody,
    I want to know How To Free Memory from my app.

    Thank you all in advance,
    ERAN
    Eran Fox
    ASSEMBLER,C,C++,VB6,SQL...

  2. #2
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994

    ehm

    FROM your app? Release the memory the app uses?
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  3. #3
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    eranfox

    We would need to see the app to see where you are keeping it. Can't do it by a Seance.

  4. #4
    Hyperactive Member
    Join Date
    Oct 2000
    Location
    Sydney Australia
    Posts
    476
    My undersatnding is that there your app holds memory in two places the stack and the heap. Correctly me someone if I'm wrong.

    Heap memory is for variables you declare only with a Dim statement such as longs, strings, integers.
    Stack memory is for things you need to initialise with a Set statement such as recordsets, ado connections, dao databases.

    Heap memory is released as soon as the function in which the variables were declared is exited, so you don't need to worry.

    With stack memory the app releases any the memory the variable holds when it gets the chance to. So it may take a little while. You can get around this by setting any variables to nothing as soon at they you are finished with them. You should do this as a matter of course.

    You also need to be conscious of where you are using memory. I once had to maintain an app that made a new connection to the database every time it needed to get data. This is highly memory intentensive. This sort of code needed to be replaced with a single database connection that the whole app could use.

    Think also of big memory ticket items such as using local cursors. These bring all data into local memory, fast but expensive.

    These are just a few things for you to think about. Post us with more details of the type of app you have

    FW

  5. #5
    PowerPoster
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    2,166
    Heap hold anything declared global/public.

    Stack holds basically everything else.

    The short answer regarding freeing memory is:


    1) all items pushed on the stack (eg. private functions, variables declared within, module level variables) are freed when they go OUT OF SCOPE (no longer using them).

    1) unless you use the API, the only other memory you can normally free manually is arrays (see Erase) and objects (set object = nothing)

  6. #6

    Thread Starter
    Hyperactive Member eranfox's Avatar
    Join Date
    May 2001
    Posts
    492

    Reply

    Hello Again,
    I want to free memory - not the memory the app uses.
    I'll explain:
    Win98 dont know to free memory well
    not like other OS such as winXP OR WIN2K
    Because of that i want to be able to free/release memory by my self.

    is that possible???

    Thank you ALL,
    best regards,
    ERAN
    Eran Fox
    ASSEMBLER,C,C++,VB6,SQL...

  7. #7
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253
    I once had to maintain an app that made a new connection to the database every time it needed to get data. This is highly memory intentensive. This sort of code needed to be replaced with a single database connection that the whole app could use.
    Not true under COM+ (Win2k and later)

    The database connection is pooled so that when you get the 'new' db connection you are actually simply retrieving the old one subject to time elapsed constraints.

    This is actually one way to create very scalable components.

  8. #8

    Thread Starter
    Hyperactive Member eranfox's Avatar
    Join Date
    May 2001
    Posts
    492

    Reply

    WELL???
    I'm still waiting for your answers

    ERAN
    Eran Fox
    ASSEMBLER,C,C++,VB6,SQL...

  9. #9
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253
    . . . and we're waiting for some manners.

  10. #10

    Thread Starter
    Hyperactive Member eranfox's Avatar
    Join Date
    May 2001
    Posts
    492

    Reply to yrwyddfa

    Dear yrwyddfa ,
    I'm Sorry if i hurt your feelings...

    But...

    I think we're missing the point here!

    The point is


    I'm still waiting for your answers
    Thank you again for your reply,
    Best Regards,
    ERAN
    Eran Fox
    ASSEMBLER,C,C++,VB6,SQL...

  11. #11
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253
    Well you shouldn't be so rude. We are not a service dedicated to serving you up with answers.

    The answer you require is:

    In VB you can't, and probably shouldn't unless it is a sideeffect of a native VB function.

    If you want to have control of memory use GlobalAlloc on pre Win2k machines, and VirtualAlloc after Win2k to allocate yourself memory, and then you can do as you please with it.

    How do these work? Well, there are tons examples all over the web.

  12. #12
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    Or do you mean freeing your app from memory?

    VB Code:
    1. Private Sub Form_Unload(Cancel As Integer)
    2. 'Free memory from app
    3. Unload Me
    4. 'Terminate the app
    5. End
    6. End Sub

    Is that what you mran? Or the other stuff as suggested above?

  13. #13

    Thread Starter
    Hyperactive Member eranfox's Avatar
    Join Date
    May 2001
    Posts
    492

    Reply to yrwyddfa

    Dear yrwyddfa,
    I'm sorry!!!

    but you know,
    sometimes the threads are going out of control.

    the thread is about something but everyone trying to answer
    about different subjects - this way we miss the threads issue.

    Best Regards,
    ERAN

    have a nice day
    Eran Fox
    ASSEMBLER,C,C++,VB6,SQL...

  14. #14
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104
    .NET probably manages memory better with its garbage collection, so you could switch.

    On the other hand, what do you gain by managing memory? I would expect that you would have to have a fairly massive .exe for the VBVM not to load more .dlls into memory than your program itself. There are things you might do to save a few bytes here and there, but that probably does you no good.

    Even with memory freeing, you would only be marking the memory as freed. To really benefit, you would want to consolidate freed memory. These days, for most apps, what's the point?

  15. #15
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253
    There are things you might do to save a few bytes here and there, but that probably does you no good.
    On a system that is designed to scale massively, those few bytes add up to an awful lot of megabytes

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