String Objects in Memory after Concating in C# [closed] - c#-4.0

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I understand in C# that string is Immutable when I concat 2 strings a new object is created.
What happens to the previous objects in the memory?
Does GC remove the old object as soon as a new object is created?

When you are modifying a value of the string, i.e. you are creating a new object which refers to that modified string and the old one becomes unreferenced.
Hence, if we are modifying the existing string continuously, then numbers of the unreferenced object will be increased and it will wait for the garbage collector to free the unreferenced object.
When garbage collector run it reclaim all unused memory occupied by unreferenced objects.

Related

How do I avoid stack overflow at compile time? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
General performance advice for Rust is to try to avoid placing things on the heap if possible.
An issue I am having is that I do not know where/when the size limit of a function stack will be reached, until my program panics unpredictably at runtime.
Two examples are:
Parsing deeply nested structs from JSON using Serde.
Creating many futures inside a function.
Questions:
Can I avoid this by detecting it at compile time?
How can I know what the limit of the stack is whilst I am writing code? Do others just know the exact size of their variables?
Why do people advise to try to avoid the heap?

What is the best way to generate and run concurent threads from a for loop over an Arc<Mutex<Vec>>? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Im running both a uni and multi threaded version of an application. There is no speed advantage. That said, what is the best way to access an Arc<Mutex<Vec>> and process each entry concurrently?
You cannot process an Arc<Mutex<Vec<T>>> concurrently - the mutex wraps the entire vector, so no other thread other than the one that locked it will be able to access it.
If you know the number of elements up front, you can use an Arc<Vec<Mutex<T>>>. This has a mutex per-element, so threads will lock only the elements. However you won't be able to grow or shrink the Vec since its shared.
There are also more specialized structures in the Concurrency section of http://lib.rs, with varying semantics, that may fit your needs.

spark-memory fraction and executor memory overhead? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
what is "spark.executor.memoryOverhead" and "spark.memory.fraction"?
what is the default properties
spark.memory.fraction parameter can be used to separately understand memory available for storage and memory available for execution. If you are caching too many objects in memory then you will need more of storage (spark.memory.fraction can be 0.5/0.6). However, if you are using memory for largely execution purposes then you need memory to be available for execution (spark.memory.fraction can be 0.2/0.3).

How does Rust enforce/implement RAII [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm working on a (maybe) serious programming language and want to learn about implementing memory management. I want this language to enforce RAII, similar to Rust, but, unlike rust, this language is Object-Oriented and I hope I can implement objects that manage their own memory (like Boxes in Rust). Can anyone go into detail about how Rust handles references to Heap memory?
I think the most obvious way to implement classes is:
Your class variables are implemented as pointers, like in C# and Java.
There is a single owner of the object and all class variables have move semantics in order to enforce this, like in Rust.
Memory is a resource that needs to be cleaned up, so all class variables, after calling the destructor (if any) of the referent object, also call the deallocation routine of your memory allocator, like in C++.
You introduce lifetimes in your type system in order to ensure that lending/borrowing the object doesn't allow any non-owning references to outlive it, like in Rust.

Is it a good idea to use global variables to store DB handles in a Go web application? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Official guide says it's okay to use a global variable to cache templates:
http://golang.org/doc/articles/wiki/
First we create a global variable named templates, and initialize it
with ParseFiles.
Can global variables be used to store DB handles and repository objects? Or do they have to be initialized for every request?
Thanks a lot
Yes, that's perfectly fine, it's used in the official Go packages all over the place, now if you gonna modify these objects from your handlers, you will have to use a mutex so you wouldn't run into races.

Resources