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 8 years ago.
Improve this question
Just trying to understand the out of memory exception in dot net.
If I create a infinite while loop and in the loop I create a new object and that object writes something to a file.
Will this application run out of memory? Will this cause out of memory exception?
An OutOfMemoryException is thrown whenever the application tries and fails to allocate memory to perform an operation. According to Microsoft's documentation, the following operations can potentially throw an OutOfMemoryException:
Boxing (i.e., wrapping a value type in an Object)
Creating an array
Creating an object
If you try to create an infinite number of objects, then it's pretty reasonable to assume that you're going to run out of memory sooner or later.
(Note: don't forget about the garbage collector. Depending on the lifetimes of the objects being created, it will delete some of them if it determines they're no longer in use.)
Related
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 am curious about how clr knows particular object is not used by any other object and it is dead we know the basic of garbage collector but internally how clr find dead object.How clr knows the objects are in dead position.
https://msdn.microsoft.com/en-us/library/ee787088(v=vs.110).aspx#Anchor_4
A garbage collection has the following phases:
A marking phase that finds and creates a list of all live objects.
A relocating phase that updates the references to the objects that
will be compacted.
A compacting phase that reclaims the space occupied by the dead
objects and compacts the surviving objects. The compacting phase
moves objects that have survived a garbage collection toward the
older end of the segment.
The garbage collector uses the following information to determine whether objects are live:
Stack roots. Stack variables provided by the just-in-time (JIT)
compiler and stack walker.
Garbage collection handles. Handles that point to managed objects and
that can be allocated by user code or by the common language runtime.
Static data. Static objects in application domains that could be
referencing other objects. Each application domain keeps track of its
static objects.
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 6 years ago.
Improve this question
I want to set automatically cleaning method for a desktop running application, because it throw an error "out of memory".
Is there any way to do this?
.
There is already an "automatic cleaning method"; the GC. You should virtually never need to tell it what to do - it understands memory more than most people do. If your code is throwing OOM, you need to investigate why; for example, are you leaking objects? (static event handlers are notorious for this); are you asking for huge slabs of contiguous memory (huge arrays, etc)? are you asking for an array that is more than 2 GiB (without large array support enabled)? are you running on 32-bit and just using lots of memory? is it actually not really an OOM condition, but really GDI+ handle exhaustion (which demonstrates in the same way)?
The first thing to check is how much memory your process is using - and how much free memory the OS has - when it throws OOM. If there is plenty of free memory, it isn't actually OOM (unless you're using over 1 GiB on a 32-bit system, in which case all bets are off).
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 8 years ago.
Improve this question
I would Like to Know if there's a way to see what is in the Memory wile Debugging.
eg. see what data-tables are still active ,Where most of the memory is allocated to ect...
I know about the "Watch" Feature in VS2013 But its not really what I'm looking for,I want to know what objects i did not dispose of correctly.And to go trough it manually is HARD!Something like a memory overview.I have tried Process explorer too but it only shows how mush the process is using at the moment in total,its good to check for a Memory leak however.
If Something like this exists is there a tutorial you can point me to?
ANTS Memory Profiler will allow you analyze which objects are in memory when you expect them not to. As well as let you investigate why that is.
I'm sure there are other, similar tools.
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 9 years ago.
Improve this question
I've been hearing the term atomic variable for a while now and so far I don't no what is that,
so I'd like to see an example and why we use atomic variable if possible in C#
and thank you very much.
Atomic operations are thread-safe operations that execute atomically, that is there is no thread-switch while the operation is executing (or at least the result of a thread-switch is not observable from the outside) so practically the operation is executed as a one-step. On the .Net platform this is provided by the Interlocked class. Other platforms, such as Java provide various other classes, like AtomicInteger. An instance of the AtomicInteger (in Java) could be called an atomic variable, so I'm guessing that's what you are referring to when you say an atomic variable.
The main point about Atomic/Interlocked objects is that they don't require any outside locks or other synchronization objects to achieve atomicity and thus thread-safety.
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 9 years ago.
Improve this question
As garbage collection can't clear unmanaged code.To clear unmanaged code we use dispose method,but can vice versa possible?can we clear manage code object using dispose method?
A Dispose method implementation might set some fields to null, potentially making "child" objects eligible for garbage collection even if the containing object itself isn't eligible for garbage collection.
It can't forcibly delete objects though - the closest it could come would be to call GC.Collect.
Dispose certainly doesn't have to clear fields at all though - for example, with MemoryStream, you can access the data within the stream (via ToArray or GetBuffer) even after disposing of it.
Usually it's better (IMO) to just let the garbage collector get on with what it's good at.
If you really need to force this - you could implement IDisposable on your class and then use it within a using(){} block once it falls out of scope it will be cleaned up on the next GC.Collect cycle, which can be forced by calling the method.