Answer the question
In order to leave comments, you need to log in
Should the generation of events for graphic elements be disabled?
There are such controls as labels and panels that carry only graphic value.
They don't have registered event handlers.
Is memory allocated for events for which there are no handlers?
Is memory allocated for waiting for event handler registrations all of a sudden?
Answer the question
In order to leave comments, you need to log in
Both label and panel inherit from the Windows.Forms.Control class, respectively, they are "child" windows (window) in relation to the main one.
To answer your question, you need to understand what "under the hood" is an event.
When registering a new window in the system, memory is allocated for the program code (window procedure WNDPROC ) that processes incoming messages (Windows Message). For certain classes (form), handlers have already been generated in it that respond to basic messages (window moving, minimizing, resizing, redrawing, etc.). All windows have a window procedure.
When you write an event handler, what you are really doing is passing the address of that handler to the window's window procedure, saying that if a particular Window Message arrives, the program code at that address should be executed.
Accordingly, if you have not written an event handler, then no additional. memory is not allocated by the system (I don't know, however, whether the compiler optimizes "empty" event handlers).
2. "Suddenly" in a compiled language is impossible without black magic and metaprogramming. All your program code is compiled and memory is allocated for it when the application starts. But you can pass a new parameter to a window procedure during execution by subscribing to a particular message, or unsubscribing from it. Depending on this, memory is allocated by the operating system for all compiled code.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question