How is memory management different in Java and C #?

I read the 2010 CWE / SANS Top 25 most dangerous programming errors , and one of the entries is a Buffered copy without checking the size of the input . It suggests using a language with features to prevent or mitigate this problem and says:

For example, many languages ​​that perform their own memory management, such as Java and Perl, are not subject to buffer overflows. Other languages, such as Ada and C #, usually provide overflow protection, but the programmer can disable protection.

I did not know that Java and C # are significantly different in terms of memory management. How is Java not prone to buffer overflows, and C # only protects against overflows? And how can you disable this protection in C #?

+3
source share
2 answers

java does not support source pointers (strictly speaking, this does not support pointer arithmetic).

In C #, you can use unsafe code and pointers and unmanaged memory, which makes buffer overflows possible. See unsafe keyword.

For security and type safety, C # does not support pointer arithmetic, by default. However, by using the unsafe keyword, you can define an unsafe context in which pointers can be used. For more information on pointers, see topic Types of Pointers .

+4

. , Java . # . raw- - #, C. # C/++ , . "" , 2 ( # CLR, Java JVM), - . # , , , .

, , " " "". , - , C... MEMORY LEAK. , ( ). # "" . , . C-, "".

" " "Pro # 2010 .NET Platform" . -, . - MSDN Finalize Dispose

. (~ ObjectName() {...}). , , , . , , .

+3

Source: https://habr.com/ru/post/1737273/


All Articles