LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Using LocalizeMenuBar

I am currently using Labwindows/CVI 7.0.0.  Everytime I called LocalizeMenuBar, my total number of bytes allocated keeps growing. I used CVIDynamicMemoryInfo to check the total number of bytes. Is this a bug in this version or am I doing something wrong? Thanks in advance.
 
KV1
0 Kudos
Message 1 of 9
(4,207 Views)

I forgot to mention that using DiscardMenuBar did not seem to help.

KV1

0 Kudos
Message 2 of 9
(4,191 Views)
Hi, KV1,

Can you post a simple example for us to look at?

Song D
Regards,

Song Du
Systems Software
National Instruments R&D
0 Kudos
Message 3 of 9
(4,172 Views)
Thanks for your reply.  From the attached code sample, one call to LocalizeMenuBar produce total # of blocks allocated = 6 and total # of bytes = 192; two calls produce # blocks = 12 and # bytes = 384; and keeps increasing as I increase the number of calls to the function by switching back and forth between Spanish and English.
 
#include <utility.h>
#include "localui.h"
#include <cvirte.h>  
#include <userint.h>
#include "LoadMenuBarTest.h"
#include "menu.h"

static int panelHandle, menuPanel;
static int menu = 0;

int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                       LPSTR lpszCmdLine, int nCmdShow)
{
 if (InitCVIRTE (hInstance, 0, 0) == 0)
  return -1; /* out of memory */
 if ((panelHandle = LoadPanel (0, "LoadMenuBarTest.uir", PANEL)) < 0)
  return -1;
 
 if ((menuPanel = LoadPanel (0, "menu.uir", MENUPANEL)) < 0)
  return -1;
 menu = LoadMenuBar (0, "menu.uir", MENU);
 
 DisplayPanel (panelHandle);
 
 RunUserInterface ();
 
 DiscardPanel (panelHandle);
 DiscardMenuBar(menu);
 DiscardPanel (menuPanel);
 
 //////////////////////
 CVIDynamicMemoryInfo ("Dynamic Memory", NULL, NULL, DYNAMIC_MEMORY_SHOW_ALLOCATED_MEMORY);
 //////////////////////
 return 0;
}

int CVICALLBACK Quit (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 if (event == EVENT_COMMIT) {
  QuitUserInterface (0);
 }
 return 0;
}

int CVICALLBACK ShowMenuPopup (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 int itemSelected = 0;
 
 if (event == EVENT_COMMIT) {
  itemSelected = RunPopupMenu (menu, MENU_LANGUAGE, panel, 0, 0, 0, 0, 0, 0);
  if (itemSelected == MENU_LANGUAGE_SPANISH) {
   LocalizeMenuBar(menu, "lang_span.lwl");
   SetMenuBarAttribute (menu, MENU_LANGUAGE_SPANISH, ATTR_CHECKED, 1);
   SetMenuBarAttribute (menu, MENU_LANGUAGE_ENGLISH, ATTR_CHECKED, 0);
  }
  else if (itemSelected == MENU_LANGUAGE_ENGLISH) {
   LocalizeMenuBar(menu, "lang_engl.lwl");
   SetMenuBarAttribute (menu, MENU_LANGUAGE_SPANISH, ATTR_CHECKED, 0);
   SetMenuBarAttribute (menu, MENU_LANGUAGE_ENGLISH, ATTR_CHECKED, 1);
  } 
 }
 return 0;
}
 
0 Kudos
Message 4 of 9
(4,160 Views)
Hi, KV1,

Nothing looks out of normal in your code. Is it possible for you to zip up the entire project so I can run it on my end.

Song D
Regards,

Song Du
Systems Software
National Instruments R&D
0 Kudos
Message 5 of 9
(4,149 Views)
I have attached the zip file.  Thanks.
 
KV1
0 Kudos
Message 6 of 9
(4,146 Views)
Hello, Song D and everyone,
 
Did anyone get a chance to take a look at my attached sample project from 9/25/07?  Thanks.
 
KV1
0 Kudos
Message 7 of 9
(4,111 Views)
KV1,

Yes, I got your file and I was able to reproduce the memory usage increase. I am contacting R&D to find the cause of it.

Song D
Regards,

Song Du
Systems Software
National Instruments R&D
0 Kudos
Message 8 of 9
(4,100 Views)
Hi, KV1,

We have found that there is a memory leak with the LoadMenuBar function. What we're thinking as a workaround is to call two LoadLocalizedMenuBar in the beginning, one for english and the other for spanish. In your ShowMenuPopup callback, you would just need to set the menu attributes. That way, you're not loading the menu bar continuously. Let us know if it works for you.

Regards,

Song D


Regards,

Song Du
Systems Software
National Instruments R&D
0 Kudos
Message 9 of 9
(4,002 Views)