Is there a limit to amount of controls. lazarus / 39-Graphics ---------------------------------------------------------------------- Josh · 2015-03-18 20:47 I am creating a app that has many controls in it, in access of 5000. These controls are on numerous panels and everything, the controls only get updated if they are visible. The problem I have is that I have a panel that has approx 500 controls on which are tbcbuttons, ( simulating 5 piano keyboards using tbcbuttons as keys so I can add text to the keys). These are created on application create event, the problem I get is when I try make this panel visible I get an Ememory error. If I reduce the piano keyboards to 3, then the panel shows fine, if I set to 4 more often than not will not show, If I set to 5 it error as soon as I set the panel visible. So I am wondering if the amount of controls on a panel has a limit, or does the application have a limit. I do have some large arrays that I have now set to dynamic so they are on the heap, thinking maybe the stack is getting full. Wondering if anyone has come up with this problem. WHen I create controls programatically ( as approx 4500 are created this way) is the info for this control in the stack or heap, done a bit of googling but couldn't find a answer. ---------------------------------------------------------------------- Never · 2015-03-18 21:22 new classes objects etc are alive in the heap about your problem : on every system there are other apps running exept yours so with this amount of controls is just a matter of time to reach  memory limits to overcome this slpit the gui to what a humman can read and create and display what is required only when is required and unload it when you are done with it. even thought i'm not aware about your app it might be a good idea to consider  using picture for your piano displays labels to set captions and create a frame with your buttons and set this frame over each image when ever you need inderaction  from the user ---------------------------------------------------------------------- Basile B. · 2015-03-18 23:22 it's easy to test by yourself until you realize that the limit is the physical memory (maybe some weird things can also happend with GDI handles under win): Code: [Select]procedure TForm1.Test; var   Ctrl: TPanel;   i : Uint64; begin   while (true) do begin     try       Ctrl := TPanel.Create(self);       Ctrl.parent := self;       i += 1;    except       // i indicates the possible amount of ctrl on this system...       break;     end;       if i = high(Uint64) then         break;    end; end; ---------------------------------------------------------------------- Josh · 2015-03-18 23:39 Hi Thanks for your responses. @Never I think I may have to try creating the controls before I show the Panels and see if that helps. @Basile B I done a similar test, and created way more than I was using across multiple panels. The problem is odd in that the panel is created with the controls on successfully, no errors. A soon as I set that panel to visible the error occur, I do not even see the panel appear. ---------------------------------------------------------------------- Mike.Cornflake · 2015-03-19 01:11 Quote from: josh on March 19, 2015, 12:39:46 amA soon as I set that panel to visible the error occur, I do not even see the panel appear. If the problem is simply panels 4 and above not being visible, then I think we will need to see code. If your whole PC wobbles (and maybe even crashes) when you show panel 4 and above, then you have exceeded the Windows GDI Count, and Windows *STILL* can't handle that (pun intended). I think the Max GDI count for modern windows is 10,000. I have problems with GDI Count in my own app - I know the solution to my particular issue - don't have a TImageList with 100+ small icons in it in a base form.  If exceeding 10000 GDI objects is indeed your problem, then the only solution is to NOT exceed the GDI count :-)  You can add GDI Objects as a column in Task Manager - find your app, see what the GDI Object count is.  If it's low, this isn't your problem... Update:  New limit could be 16K, not 10K https://msdn.microsoft.com/en- us/library/windows/desktop/ms724291%28v=vs.85%29.aspx ---------------------------------------------------------------------- Basile B. · 2015-03-19 01:32 Quote from: josh on March 19, 2015, 12:39:46 amHi Thanks for your responses. @Never I think I may have to try creating the controls before I show the Panels and see if that helps. @Basile B I done a similar test, and created way more than I was using across multiple panels. The problem is odd in that the panel is created with the controls on successfully, no errors. A soon as I set that panel to visible the error occur, I do not even see the panel appear. With my example you'll necessarily have something like an OutOfMemory error, even on a 64 bit system, this will allocate up to $FFFFFFFFFFFFFFFF * TPanel.instanceSize bytes which exceeds the maximum memory a 64 bit OS is able to manage (2^64). And it supposes that the same amount of DRAM would be setup...what it this amount nowadays ? 32 GB in the better cases ? Even each byte of a the biggest hard drive of the market can be indexed in a Uint64...