Results 1 to 15 of 15

Thread: Out of memory in an apparent benign place

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2001
    Location
    Europe
    Posts
    289

    Out of memory in an apparent benign place

    Hi,

    I have this app which admittedly uses only one main form with something like 250 instances of twelve control arrays that were placed at design time.

    The problem is under NT/2k/XP the app loads fine, but under W9x, the app just crashes with out of memory error. The total size of the app is 8MB.

    Can someone suggest a reason why this is. I tried on Win98 and ME and the problem persists.

  2. #2
    Si_the_geek
    Guest


    how many controls???

    that sounds like far too many to me, and is blatantly the problem - reduce the number of controls somehow!

    as a rough guide you shouldn't really have any more than about 100 controls in total, including control array elements!

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2001
    Location
    Europe
    Posts
    289
    ok Si_the_geek I will try it without so many controls. The problem is I need it as it is because this app is used to control remote pc's and we want to offer functionality (start session, stop,...) for 250 pc's.

    Is there an apparent reason why it should be ok with win 2k/xp byt not win 9x. How can identify why it is working on win 2k and not the others?.

    Many thanks !

    Mike.

  4. #4
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828


    my heart just stopped.


    may need to reduce controls, at least 2 or 3 should be removed
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2001
    Location
    Europe
    Posts
    289
    Hi again,

    I still have the same problem eventhough I reduced the arrays down to 50 instances.

    What I have is the following:

    * A sub main:

    Option Explicit
    Private Sub Main()

    SplashScreen.Show ' Show the splash screen.

    Call SurfForm.LoadData 'load form and its data

    Unload SplashScreen
    SurfForm.Show ' Show the main form and unload the splash screen.
    End Sub

    *Declarations in the SurfForm code:

    Option Explicit

    Private Declare Function GetAsyncKeyState Lib "User32" (ByVal vKey As Long) As Integer
    Private Declare Function GetDesktopWindow Lib "User32" () As Long
    Private Declare Function GetWindow Lib "User32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
    Private Declare Function GetParent Lib "User32" (ByVal hwnd As Long) As Long
    Private Declare Function GetWindowTextLength Lib "User32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
    Private Declare Function GetWindowText Lib "User32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function SetCapture Lib "User32" (ByVal hwnd As Long) As Long
    Private Declare Function ReleaseCapture Lib "User32" () As Long
    Private Declare Function GetCapture Lib "User32" () As Long

    Private Const WM_CLOSE = &H10
    Private Const GW_HWNDFIRST = 0
    Private Const GW_HWNDNEXT = 2
    Private Const GW_CHILD = 5

    Private frmDet As ConfirmDialog
    Private frmDet1 As ConfirmWithCanteenDialog
    Private fFrmDetCol As New Collection
    Private fFrmDetCol1 As New Collection

    Dim licenceProbl As Boolean
    Dim PCNbr As String
    Dim reportErr As Boolean
    Dim intMax As Long
    Dim thatPath As String, thatPath1 As String, thatPath2 As String
    Dim bAcked As Boolean ' send acknowledged
    Dim FileN As Long
    Dim UniqueID As Integer
    Dim lclHost As String
    Dim SerialNumber As Long
    Dim msg As String, Title As String, Style As String
    Dim blnState As Boolean
    Dim scndState As Boolean
    Dim fisrtCh1 As String
    Dim fisrtCh2 As String
    Dim fisrtCh3 As String
    Private stopWatch() As New CStopWatch
    Dim isClosed As Boolean
    Dim homeP As String
    Dim tempstr As String
    Dim costsStr() As String
    Dim pauseStat() As Boolean
    Dim firstSecnd() As Boolean
    Dim menuOrder() As Boolean
    Dim haveStop() As Boolean
    Dim costMode As String
    Dim CLocale As CLocale1 'new object to get locale settings
    Dim strSql As String
    Dim dateSlsh1 As String
    Dim myDbCon As New ADODB.Connection
    Dim myDb As Database
    Dim ConnectDB$
    Dim MenuTable As DAO.Recordset
    Dim OrdersTable As DAO.Recordset
    Dim EventsTable As DAO.Recordset
    Dim SessionsTable As DAO.Recordset
    Dim ccyStr As String
    Public ActivePrinter As EventVB.ApiPrinter
    Public WithEvents apiLink As EventVB.APIFunctions

    * And some functions I call in Load_Data:

    Public Function LoadData()

    Dim h As Integer

    On Error GoTo ErrTrap

    'Set apiLink = New EventVB.APIFunctions

    reportErr = False
    PCNbr = "0"

    Call checkIsrunning 'checking the app is not already running
    Call checkPSWD
    Call CheckLcce
    Call CheckCurr
    Call CheckPC

    SplashScreen.ProgressBar1.Max = (3 * CInt(PCNbr)) + 4

    Call SplashScreen.UpdateStatus(0) 'updating splash screen progress bar
    Call PopulateForm
    Call SplashScreen.UpdateStatus(1 + CInt(PCNbr)) 'updating splash screen progress bar
    Call CreateObjs
    Call SplashScreen.UpdateStatus(2 + 2 * CInt(PCNbr)) 'updating splash screen progress bar
    Call PopCurrBoxes
    Call SplashScreen.UpdateStatus(3 + 3 * CInt(PCNbr)) 'updating splash screen progress bar
    Call ActuaStations.ReduceStat(CInt(PCNbr))
    Call SplashScreen.UpdateStatus(4 + 3 * CInt(PCNbr)) 'updating splash screen progress bar
    'Call PrintDialog.SetActivePrinter 'activating the printer

    ErrTrap:
    If Err.Number <> 0 Then
    Call SurfForm.insertIntoEvents(CStr(Format(Now, "mm/dd/yyyy hh:mm:ss")), CStr(0), Err.Description, Err.Number, "Svr-Srffm2")
    End If
    End Function

    ...and this is really bugging me. I use some dll I found on the net called EventVB.dll. Maybe this is the problem ???

    Help please...!

    Mike

  6. #6
    Frenzied Member KayJay's Avatar
    Join Date
    Jul 2001
    Location
    Chennai
    Posts
    1,849
    Can you pin-point before what line of code the app crashes. An append-to-logfile should keep track of the execution each line of code.

    "Brothers, you asked for it."
    ...Francisco Domingo Carlos Andres Sebastian D'Anconia

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2001
    Location
    Europe
    Posts
    289
    Hi KayJay,

    I have done the reverse method, by adding the controls to the blank form and yes it will only allow me to put in 40 instances of the 12 control arrays before crashing. This is against 250 under W2k/XP. I wonder what makes it impossible for Win95/98/Me to take more.

    Does anyone know as there might be a work around somehow?!?

    Thanks.

    Mike

  8. #8
    Frenzied Member KayJay's Avatar
    Join Date
    Jul 2001
    Location
    Chennai
    Posts
    1,849
    just a thought.

    VB Code:
    1. Declare Function SetThreadPriority Lib "kernel32" Alias "SetThreadPriority" (ByVal hThread As Long, ByVal nPriority As Long) As Long
    its parameters are
    · hThread
    Identifies the thread whose priority value is to be set.
    Windows NT: The handle must have the THREAD_SET_INFORMATION access right associated with it. For more information, see Thread Objects.

    · nPriority
    Specifies the priority value for the thread. This parameter can be one of the following values:
    THREAD_PRIORITY_ABOVE_NORMAL
    Indicates 1 point above normal priority for the priority class.
    THREAD_PRIORITY_BELOW_NORMAL
    Indicates 1 point below normal priority for the priority class.
    THREAD_PRIORITY_HIGHEST
    Indicates 2 points above normal priority for the priority class.
    THREAD_PRIORITY_IDLE
    Indicates a base priority level of 1 for IDLE_PRIORITY_CLASS, NORMAL_PRIORITY_CLASS, or HIGH_PRIORITY_CLASS processes, and a base priority level of 16 for REALTIME_PRIORITY_CLASS processes.
    THREAD_PRIORITY_LOWEST
    Indicates 2 points below normal priority for the priority class.
    THREAD_PRIORITY_NORMAL
    Indicates normal priority for the priority class.
    THREAD_PRIORITY_TIME_CRITICAL
    Indicates a base priority level of 15 for IDLE_PRIORITY_CLASS, NORMAL_PRIORITY_CLASS, or HIGH_PRIORITY_CLASS processes, and a base priority level of 31 for REALTIME_PRIORITY_CLASS processes.
    See if you can load more, if not all, by setting a higher priority to your app's thread. Logically, if your app has the highest priority possible it should be able to access the maximum resources that can be marshalled.

    "Brothers, you asked for it."
    ...Francisco Domingo Carlos Andres Sebastian D'Anconia

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2001
    Location
    Europe
    Posts
    289
    Hi,

    This is great, I'll try this now.

    Cheers,

    Mike

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2001
    Location
    Europe
    Posts
    289
    Hi Kay-Jay,

    I tried the code, but still get the same problem.

    The usage I have for this code is as follows (taken from all-api)

    Const THREAD_BASE_PRIORITY_IDLE = -15
    Const THREAD_BASE_PRIORITY_LOWRT = 15
    Const THREAD_BASE_PRIORITY_MIN = -2
    Const THREAD_BASE_PRIORITY_MAX = 2
    Const THREAD_PRIORITY_LOWEST = THREAD_BASE_PRIORITY_MIN
    Const THREAD_PRIORITY_HIGHEST = THREAD_BASE_PRIORITY_MAX
    Const THREAD_PRIORITY_BELOW_NORMAL = (THREAD_PRIORITY_LOWEST + 1)
    Const THREAD_PRIORITY_ABOVE_NORMAL = (THREAD_PRIORITY_HIGHEST - 1)
    Const THREAD_PRIORITY_IDLE = THREAD_BASE_PRIORITY_IDLE
    Const THREAD_PRIORITY_NORMAL = 0
    Const THREAD_PRIORITY_TIME_CRITICAL = THREAD_BASE_PRIORITY_LOWRT
    Const HIGH_PRIORITY_CLASS = &H80
    Const IDLE_PRIORITY_CLASS = &H40
    Const NORMAL_PRIORITY_CLASS = &H20
    Const REALTIME_PRIORITY_CLASS = &H100

    Private Declare Function SetThreadPriority Lib "Kernel32" (ByVal hThread As Long, ByVal nPriority As Long) As Long
    Private Declare Function SetPriorityClass Lib "Kernel32" (ByVal hProcess As Long, ByVal dwPriorityClass As Long) As Long
    Private Declare Function GetThreadPriority Lib "Kernel32" (ByVal hThread As Long) As Long
    Private Declare Function GetPriorityClass Lib "Kernel32" (ByVal hProcess As Long) As Long
    Private Declare Function GetCurrentThread Lib "Kernel32" () As Long
    Private Declare Function GetCurrentProcess Lib "Kernel32" () As Long

    In Form_Load, i have:

    'retrieve the current thread and process
    hThread = GetCurrentThread
    hProcess = GetCurrentProcess
    'set the new thread priority to "lowest"
    SetThreadPriority hThread, THREAD_PRIORITY_HIGHEST
    'set the new priority class to "idle"
    SetPriorityClass hProcess, HIGH_PRIORITY_CLASS

    Something i forgot is that when in Visual Studio, I try to load the form by clicking on it, the compiler itself goes haywire and I get an hourglass. I then cannot get back to çwindows. Then, if I do ctrl-alt-del, Windows crashes.

    This is really bizarre to the extreme, how Win9x is left really wanting like this.

    Mike

  11. #11
    Frenzied Member KayJay's Avatar
    Join Date
    Jul 2001
    Location
    Chennai
    Posts
    1,849
    First: I am advised by my colleague (who was shoulder surfing, as usual) to avoid setting up priorities manually without really knowing how it will affect the OS. System Crashes are more liable.

    That apart...

    Try having DoEvents or the Sleep() function between loading controls. It will delay the whole thing a lot, but if it works, it should be worth it. I can not think of anything else now. Got to go home and hit the hay!

    "Brothers, you asked for it."
    ...Francisco Domingo Carlos Andres Sebastian D'Anconia

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2001
    Location
    Europe
    Posts
    289
    Ok. Many thanks for the help.

  13. #13
    Si_the_geek
    Guest
    Why can't you just use a combobox to set the PC, and single buttons etc to select what to do, which reference the PC set in the combo box?

    Or even the combo for the PC, and a listbox or two for the functions?
    Attached Images Attached Images  

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2001
    Location
    Europe
    Posts
    289
    Hi,

    Thanks. I know there could be a number of alternative ways, but the look and feel of our interface is a big plus for our customers. We could have used a listview with a right hand side mouse click submenu like other products but we decided to go for a full-on interface with all the buttons right there on the interface. We only were dealing with up to 50 pc's before and there were no problems. We use W2k to do the dev work. It's only yeasterday when we ported the code on Win9x that we hit a wall there with so many controls on Win9x.

    I'm still puzzled as to why Win9x seems to behave in such a different way than w2k when all I do is simply boot up on WMe on my multi-boot machine. It's the same machine, different OS.

    Thanks

    Mike

  15. #15
    Si_the_geek
    Guest
    Win95/Me are different from Win NT/2000 - they look & work in similar ways, but under the bonnet they are different beasts... 95/Me are designed for simple desktop use, whereas NT/2000 are for (more stable) buisness use.

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