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 944163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:32:56+00:00 2026-05-15T22:32:56+00:00

Say we have a class with 10000 const string members. class Schema { //Average

  • 0

Say we have a class with 10000 const string members.

class Schema
{
  //Average string length is 20
  public const string ID1 = "some.constant.value";
  public const string ID2 = "some.other.constant.value";
  //...
}

Not all fields are referenced in the rest of the code. Only 10% of them is accessed on startup – their reference is assigned as a key to various dictionaries (thousands of Dictionary instances). I understand that const strings are interned – referencing a const string multiple times does not increase consumed memory by more than the size of the metadata token pointing to an offset in the interned string table.

I understand that the const strings are compiled into the assembly and thus influence the size of the compiled assembly.


At what exact time/event do these const strings consume runtime memory?

Will be all the memory needed for all the const strings taken at the time the assembly is loaded or is this delayed until the class is JIT compiled?

Can we decrease memory consumption after startup by changing something in the equation? (make the fields non-const, make the strings static fields?).

Let’s assume a Winforms application (.NET 2.0).

  • 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-15T22:32:56+00:00Added an answer on May 15, 2026 at 10:32 pm

    Const strings are compile time literals, and since the CLR uses interning for these they will stick around for as long as the application is alive.

    You may also find my answer to this question relevant.

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

Sidebar

Related Questions

let's say I have class Dummy { String a, b; public Dummy(String a, String
I have class say for example public class Item { int price; String name;
say I have: class Test { public static int Hello = 5; } This
Say I have a class with three constructors, like the one below: public class
Say I have a class that looks like this (get/set omited): class InfoClass{ String
Let's say I have a user class setup with validation like this: [MetadataType(typeof(ssUserMetaData))] public
Let's say I have data structures that're something like this: Public Class AttendenceRecord Public
Let's say we have: @Entity public class Order { @Id private int id; @OneToMany(mappedBy=order)
Say I have: class Vector3 { float x, y, z; ... bunch of cuntions
Lets say I have: class X { function a() { echo Hello, ; }

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.