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

  • SEARCH
  • Home
  • 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 6197889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:54:05+00:00 2026-05-24T03:54:05+00:00

Out of curiosity…what happens when we call a method that returns some value but

  • 0

Out of curiosity…what happens when we call a method that returns some value but we don’t handle/use it? And we also expect that sometimes this returned value could be really big. Where that value goes? Is it even created? If it is, are there any performance issues or other problems that can occur? (what is the best practice in this kind of situation?)

Let’s say we have method that does some database operations (insert, update) and returns some data in DataTable object. And I also know that this DataTable object could be really big sometimes:

public static Datatable InsertIntoDB(...) 
{
      // executing db command, getting values, creating & returning Datatable object...
      ...
      return myDataTable;
}

And then when this method is used it is called like these:

DataTable myDataTable = InsertIntoDB(...);
// this Datatable object is handled in some way

But sometimes simply like this:

InsertIntoDB(...);
// returned value not handled; Problem???

On my first thought it think the system is smart enough to see the returned value is ignored and does not cause any problems (it is simply released) but I want to be sure and hear more detailed explanation of it from someone who is more experienced in this area than me.

  • 1 1 Answer
  • 1 View
  • 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-24T03:54:05+00:00Added an answer on May 24, 2026 at 3:54 am

    The returned value (or reference, if it’s a reference type) is pushed onto the stack and then popped off again.

    No biggy.

    If the return value isn’t relevant, you can safely do this.

    But be sure that it isn’t relevant, just in case.

    Here’s some code:

        static string GetSomething()
        {
            return "Hello";
        }
    
        static void Method1()
        {
            string result = GetSomething();
        }
    
        static void Method2()
        {
            GetSomething();
        }
    

    If we look at the IL:

    Method1:

    .locals init ([0] string result)
    IL_0000:  nop
    IL_0001:  call       string ConsoleApplication3.Program::GetSomething()
    IL_0006:  stloc.0
    IL_0007:  ret
    

    Method2:

    IL_0000:  nop
    IL_0001:  call       string ConsoleApplication3.Program::GetSomething()
    IL_0006:  pop
    IL_0007:  ret
    

    Exactly the same number of instructions. In Method1, the value is stored in the local string result (stloc.0), which is deleted when it goes out of scope. In Method2, the pop operation simply removes it from the stack.

    In your case of returning something ‘really big’, that data has already been created and the method returns a reference to it; not the data itself. In Method1(), the reference is assigned to the local variable and the garbage collector will tidy it up after the variable has gone out of scope (the end of the method in this case). In Method2(), the garbage collector can get to work, any time after the reference has been popped from the stack.

    By ignoring the return value, if it really isn’t needed, the garbage collector can potentially get to work sooner and release any memory that’s been assigned. But there’s very little in it (certainly in this case), but with a long running method, hanging onto that data could be an issue.

    But far-and-away the most important thing is to be sure that the return value that you’re ignoring isn’t something that you should be acting on.

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

Sidebar

Related Questions

Out of curiosity :) Also Could any element hit that Size or would some
Out of curiosity, what is the reasoning behind typeof not being a regular method
Out of curiosity is it possible to temporarily add a character that should be
Just out of curiosity I tried overriding a abstract method in base class, and
Just out of curiosity, for applications that have a fairly complicated module tree, would
Just out of curiosity. It doesn't seem very logical that typeof NaN is number.
Out of curiosity, I thought I'd try and write a basic C++ class that
Out of curiosity, I measured the performance between static block and static method initializer.
Out of curiosity: how does the CLR dispatch virtual method calls to interface members
Out of curiosity, if I call: string txt = text; Will it call this,

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.