Results 1 to 12 of 12

Thread: Out of memory error

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2017
    Posts
    760

    Question Out of memory error

    Hello!

    I don't know why this is happening, but it happens like once a year until I do something specific.

    When I try to add code or save it, it says "Insufficient memory".

    Last time, I had to make 1 .bas file smaller by moving the code to a different module.

    Another time, there was a problem with a .tlb. It took me days to find that out.

    I have it again now, and I have no idea how I could investigate this.
    I only had the idea of using procmon to see what it does when it happens.

    Here is what it shows. The last entry is "CreateFileMaping C:\Windows\SystemREsources\imageres.dl.mun"

    Name:  procmon.jpg
Views: 393
Size:  10.5 KB

    I have a really huge public enum with 1435 members, I am not sure if that might be the trouble.
    Last edited by tmighty2; Apr 21st, 2023 at 06:18 PM.

  2. #2
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,909

    Re: Out of memory error

    If I remember correctly, there is a limit to the size (lines, I believe) of a single procedure. And, I believe, VB6 treats a module's header as a procedure. So yeah, your huge enumeration may be your problem.

    Also, you posted in the CodeBank. I notified the moderators and I'm sure they'll move it shortly.

    -----------------

    ADDED: Yeah, it's apparently bytes. From the local MSDN:

    When compiled, the code for a procedure can't exceed 64K.
    ADDED2: I've never seen a limit on module size, and I've written a few large ones in the past.
    Last edited by Elroy; Apr 21st, 2023 at 06:52 PM.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  3. #3
    PowerPoster VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,619

    Re: Out of memory error

    You'd be hard-pressed to write a single procedure larger than 64K in code let alone compiled size, haha!

  4. #4
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,653

    Re: Out of memory error

    I've done it before.

    It was for a pseudo-scripting language for my crazy overengineered file renamer. I had one function for all the tokens (which was easier to call recursively so they could be nested inside eachother like a(b(c),d) etc)... so implementations for Left, Right, Mid, InStr, and dozens upon dozens more, all surrounded by some boilerplate parsing code. Eventually I ran into the limit and split off specialized function groups (mp3 tag functions, EXIF functions).

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2017
    Posts
    760

    Re: Out of memory error

    Perhaps this is some problem in my code:

    ' Note: Namespacing with VBA.Mid$ doesn't work properly here, throwing compile error:
    ' Function call on left-hand side of assignment must return Variant or Object
    Mid$(json_Buffer, json_BufferPosition + 1, json_AppendLength) = CStr(json_Append)

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2017
    Posts
    760

    Re: Out of memory error

    I even recorded my actions using a screen recorder, but it was so weird that I still don't understand why it works now.
    After each restart of VB6, a different problem appeared. Always the same error "Out of memory", but pointing a different lines of code.
    All starting with "VBA."

  7. #7
    PowerPoster VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,619

    Re: Out of memory error

    Quote Originally Posted by tmighty2 View Post
    Perhaps this is some problem in my code:

    ' Note: Namespacing with VBA.Mid$ doesn't work properly here, throwing compile error:
    ' Function call on left-hand side of assignment must return Variant or Object
    Mid$(json_Buffer, json_BufferPosition + 1, json_AppendLength) = CStr(json_Append)
    Remove the "$" from "Mid$" if you want it to return a Variant as the error message suggests.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2017
    Posts
    760

    Re: Out of memory error

    Thank you. The enum wasn't the problem. I have split it into 2, but that didn't fix it.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2017
    Posts
    760

    Re: Out of memory error

    I have registered a dll, and so far the problem has not occured yet.
    I will report back if it has.

    C:\Windows\SysWOW64\regsvr32.exe MSSTDFMT.DLL

    Got it from here: https://stackoverflow.com/questions/...f-memory-error
    Last edited by tmighty2; Apr 24th, 2023 at 03:02 PM.

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2017
    Posts
    760

    Re: Out of memory error

    I have finally found out what is happening.

    I have too many enums or duplicates of enums or enums not distinct.
    Which of the 3 I am not sure yet, but I can definitively say that enums are the culprit.

    I started putting them into an external activex exe to make them available in my project, and the error is gone.
    When I add them back into, I get the error immediately.

  11. #11
    Fanatic Member
    Join Date
    Feb 2019
    Posts
    924

    Re: Out of memory error

    Put the enums on a spreadsheet and sort to see if you have duplicates.

  12. #12
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,909

    Re: Out of memory error

    WOW, I feel like quoting my own post #2, just to make the point again.

    Per Microsoft, procedures can't be larger than 64kB. And the stuff in a module header is also consider a procedure, so that's also limited to 64kB.

    Personally, it sounds to me like it's time for you to learn about TypeLibs, and throw all these Enums into a TLB file. Done that way, it completely circumvents any VB6 procedure size limits, and also makes your code much cleaner.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

Tags for this Thread

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