Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4588720
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:57:44+00:00 2026-05-21T21:57:44+00:00

There are many many similar links in stackoverflow, all which seem to be addressing

  • 0

There are many many similar links in stackoverflow, all which seem to be addressing complex functions (so quite difficult for me to understand what i really should go for). But mine is simple. I just want to know if declaring a function as static right way to go, if i can manage the same functionality even with a nonstatic approach? Which approach utilizes more memory?

Here’s a sample code I’ve to implement, which is just showing up forms:

    private void btn1_Click(object sender, EventArgs e)
    {
        Form1 frm = new Form1();
        frm.ShowDialog();
    }

Now I’ve to show this Form1 from many other forms in my program. So should it be better (right coding practice) to write the above piece of code where ever I want Form1 to be displayed, or should it be better to define it once as a static method in a static class, like this:

public static class globalvars
{
    public static void Form1Show()
    {
        Form1 frm = new Form1();
        frm.ShowDialog();
    }

}

And then:

    private void btn1_Click(object sender, EventArgs e)
    {
        globalvars.Form1Show();
    }

I think if object of form is instantiated under the event where we want the form to be displayed (first non static approach), then the memory allocated for that process in the stack is destroyed right after its execution; while in the second static approach, the memory allocated stands throughout the lifetime of the application, and hence non-static approach is better right?

I know both works, and doesn’t make a big difference, but still, which is the right coding practice, memory usage wise?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T21:57:45+00:00Added an answer on May 21, 2026 at 9:57 pm

    Maybe I lost something there, but I didn’t see any difference between them. The frm is a local variable, not a static field.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are many similar questions, but apparently no perfect match, that's why I'm asking.
I realize that there are many similar questions, but most involve scaling down the
I know there are many questions similar but any of them didn't help. in
There are many ways of converting a String to an Integer object. Which is
There are many things that all programmers should know, but I am particularly interested
There are many similar questions, but I've tried about 15 different preg_match examples and
I'm trying to link all this technologies, but there are many isolated examples and
I have found some similar questions like this one, however there are so many
I have seen many somewhat similar questions, but nothing quite what I'm looking for.
There are many conflicting statements around. What is the best way to get the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.