How to know the size of an object in memory ? c#

Asked

Viewed 56 times

0

Just to put it in context, I’m upgrading an image search engine and need to save the previous search to the session:

public static void SavePreviousSearch(APIStandardSearchResponse search)
{
    HttpContext.Current.Session[PREVIOUS_SEARCH_KEY] = search;
}

And I call it within a search process in which I mount a APIStandardSearchResponse:

SearchCookieController.SavePreviousSearch(APIStandardSearchResponse);

Then when necessary I retrieve this object:

APIStandardSearchResponse previousSearch = SearchCookieController.GetPreviousSearch();

I would like to know the memory space (on the server) that the object previousSearch is occupied. It is possible to do this with the c#?

  • But if the session is being stored as a cookie, it is not in memory, it is literally a cookie on the server.

  • @Leandroangelo is like a physical file, type saved in hard drive/ssd ?

  • It actually depends on the way you chose to store, take a look here https://www.c-sharpcorner.com/UploadFile/3d39b4/introduction-toAsp-Net-session/

  • But why are you worried about it? You are planning to store a large volume of data in Session?

  • So Leandro, I have a list inside this object with another 100 objects (search results) then I was afraid because each user I search will store this search in Session...

  • I do not know how much memory these objects use, so that in the future when increase the number of users I do not have this problem

  • The reason for storing is not the case, but it is necessary to store in some way.

  • Maybe dup https://answall.com/q/199618/101

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.