A Developer Journey who codes for fun

Daily Dose Of Code

  • Home
  • Dot.Net Basics
    • .Net Basics
      • CTS
      • CLS
      • CLR
      • Strong Vs Weak Ref
      • .Net Framework
      • What is Manifest
    • Memory Management
      • Garbage Collection 1
      • Garbage Collection 2
      • Circular Reference
  • C Sharp
    • Abstract Class in C#
    • Interfaces in C#
    • Value type by Val and By Ref
    • Var keyword
    • Null Coalescing Operator
    • Buit-in code snippets
  • OOPS
    • Abstraction and Encapsulation
    • Polymorphism
    • Inheritence
    • Aggregation
  • Threading
    • Delegates
      • Calling Delegate using Invoke, BeginInvoke
      • Multicast Delegate
      • Exception Handling in Multicast Delegate
      • Action
      • Predicate
      • Func
    • Synchronization
    • Thread Pool
    • Exception Handling
    • TPL
  • Design Pattern
    • Creational Patterns
      • Singleton Pattern
      • Factory Pattern
      • Abstract Factory Pattern
      • Prototype Pattern
      • Builder Pattern
    • Structural Patterns
      • Adapter Pattern
      • Bridge Pattern
      • Composite Pattern
      • Proxy Pattern
      • Facade Pattern
      • Decorator Pattern
      • Flyweight Pattern
    • Behavioral Patterns
      • Command Pattern
      • Interpreter Pattern
      • Iterator Pattern
      • Mediator Pattern
      • Memento Pattern
      • Observer Pattern
      • State Pattern
      • Strategy Pattern
      • Visitor Pattern
      • Chain Of Responsibility Pattern
      • Template Pattern
  • Data Structures
    • Generic List in C#
    • 2d array to 1d array
    • 3d arrayto 1d array
    • Linked List
      • Singly Linked List in C#
    • Queue
      • Dummy Data 1
    • Stack
      • Dummy Data 2
    • Tree
      • Dummy Data 3
    • Graph
      • Dummy Data 4
  • WCF
    • WCF Service using VS 2015
  • Scripts
    • Chrome Extensions
      • Create a Chrome Extension
      • Facebook autologout script
      • Gmail autologout script

Strong Vs Weak References

 Unknown     12:41 PM     .Net Architechture     3 comments   

Strong Reference -  As long as if application refers to the object. GC will not collect those objects. Those objects we say are strong reference objects.

Weak Reference - Even though application refers to the object, GC may collect those object or may not be. Those objects are weak referenced objects.

Confused ? Let me explain in brief -

We all know GC is a non deterministic background process so we do not know when it will be called. So only weak referenced objects may reside in the memory for the long time or may not be. So it's up to us whether we want our weak references in memory or not. Lets look over the below examples -

Weak references are of two types -

Short Lived: Short weak references looses the reference when GC comes into the picture


Long Lived: Long weak references retained in the memory even GC comes and reclaims the memory. so it means it's not been collected even the Finalizer of the method is called.

How can we create Weak References ?

WeakReference objWeakReference = new WeakReference(null);

How we can achieve this long lived weak References ?

 WeakReference objWeakReference = new WeakReference(null, true);

So now you can easily see this if you want to create a long lived object then you need to set trackResurrection variable to true to stop tracking of a particular object.

So in this way you can create a weak reference. Lets understand this with one example -

So in the above code i am casting my weak reference to strong reference(as i know my strong references will not be collected by GC anyways) and checking whether it's null or not. If it is null or reclaims by GC then i am creating those strings again otherwise weak reference will fetch it from the memory.

You can also check whether your reference is alive or not.

objWeakReference.IsAlive; will return you bool whether the object is in memory or not.

Hope you enjoyed reading the article.

Happy Coding :)









Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

What is Common Type System ?

 Unknown     10:42 AM     .Net Architechture     No comments   

CTS - Common Type System as name suggest it define types. How types are defined, declared , used and managed by common Language Runtime.? The main part is it supports cross language type integration. Confused ? Let me give you a simple example.

In C# i will define my Integer variable as int and in VB.Net i will say Integer. So when i will try to see the IL code in ILDASM tool .net treats both variable as Int32. The way of writing an integer may be different in different languages in .Net but Machine instructions are same and this is possible just because of Common Type System.

So that was the basic definition and understanding of CTS. Lets look over the types supported by CTS in .Net -
  1. Class
  2. Structure
  3. Delegates
  4. Interface
  5. Enumerations
We all know about above types  will discuss this in my later articles

Type Definitions supported by CTS in .Net -
  1. Access Modifiers( Type accessibility ) - Public, Private, protected, Internal, Protected Internal
  2. Attributes - We can define our custom attributes and provide additional details
  3. Base Types - You can derive your class with Base class, not more than one
  4. Interfaces - You can implement multiple inheritance using Interface
Type Members supported by CTS in .Net - 
  1. Fields
  2. Properties
  3. Indexes
  4. Methods
  5. Events
  6. Constructors
We all know about the type members i have defined above will discuss in later articles. So these are important things CTS takes care of in .Net

Hope you enjoyed reading the article.
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

What is Common Language Specification ?

 Unknown     10:14 AM     .Net Architechture     No comments   

CLS is more about rules of .Net and it's a subset of CTS(Common Type System). You must be thinking of CTS, don't worry will discuss in my next article.

So CLS, is a basic set of language rules needed by the applications. CLS ensures Interoperability on other .Net languages. So if i want my C# code can communicate with VB code then it should be CLS compliant. If i will voilate any of C# compliant rule my VB.Net code will not be able to communicate with my C# code.

Now you must be thinking how i can assure my code is CLS compliant. So you can write an attribute in your assembly - Assembly.cs file.

[assembly : CLSCompliant(true)]

So after that whenever you will be breaking any of the rule you will get a warning in your code and CLS Compliancy

If you are interested in reading the CLS rules then visit  here

So now you understand about CLS now i will discuss some code to see live example -  



So now if i try to access my non compliant code in other language, I will not be able to use that. So using those warnings i can see that whether my code is CLSCompliant or not.



Hope you enjoyed reading the article.Let me know if you have any queries.


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Newer Posts Older Posts Home

About The Author

Unknown
View my complete profile

Total Pageviews

Popular Posts

  • Predicate delegate in C#
    Hello Everyone, In the article we will talk about Predicate delegate. Predicate is also a delegate which encapsulate a method that takes...
  • Clr - Common Language Runtime
    .Net framework provides a run time environment - CLR. Common language runtime takes the IL code from the compiler( language specific) and p...
  • Auto logout chrome extension for Gmail
    Hello Friends, In the last article we learned to create a sample chrome extension. Here we are going to create auto logout Gmail script as...
  • Nagarro Placement Papers..
    Ques.1 :- Seat Reservation prog for the theatre. Write a function for seat allocation for the movie tickets. Total no of seats available are...
  • What does it mean by disconnected data access architecture of ADO.Net?
    ADO.Net introduces the concept of disconnected data architecture. In traditional data access components, you make a connection to the databa...
  • .Net Framework overview
    Hello friends : Here i am writing my first article on .Net framework anyways....So the question is What is .Net Framework ? The .Net fram...
  • Calling the Delegates using Invoke(), BeginInvoke() and DynamicInvoke() ?
    Hello Guys, So in the last article we talked about What is delegate and how can we create a delegate. In this article we will discuss w...
  • C code to Check the string has valid identifier or not in.
    #include #include #include char keyword[][10]={"auto","break","case","char","const","...
  • Garbage Collection - Automatic memory management
    While thinking of this question few things are coming in my mind ~ How .Net reclaims objects and memory used by an application ? So the ans...
  • How to convert 3d array to 1d array ?
    Suppose you have to insert a value at (2,1,0) and the value is :-5 means firstly you have to find the index through (2,1,0) then you have to...

Blog Archive

  • ►  2016 (4)
    • ►  September (2)
      • ►  Sep 03 (2)
    • ►  August (1)
      • ►  Aug 28 (1)
    • ►  April (1)
      • ►  Apr 24 (1)
  • ►  2015 (12)
    • ►  September (10)
      • ►  Sep 30 (1)
      • ►  Sep 29 (1)
      • ►  Sep 28 (1)
      • ►  Sep 27 (2)
      • ►  Sep 26 (3)
      • ►  Sep 20 (1)
      • ►  Sep 19 (1)
    • ►  August (1)
      • ►  Aug 16 (1)
    • ►  March (1)
      • ►  Mar 31 (1)
  • ▼  2013 (10)
    • ►  June (1)
      • ►  Jun 16 (1)
    • ►  April (1)
      • ►  Apr 21 (1)
    • ▼  February (8)
      • ▼  Feb 18 (3)
        • Strong Vs Weak References
        • What is Common Type System ?
        • What is Common Language Specification ?
      • ►  Feb 17 (2)
      • ►  Feb 16 (2)
      • ►  Feb 15 (1)
  • ►  2012 (1)
    • ►  May (1)
      • ►  May 27 (1)
  • ►  2010 (22)
    • ►  October (14)
      • ►  Oct 21 (1)
      • ►  Oct 06 (12)
      • ►  Oct 04 (1)
    • ►  April (2)
      • ►  Apr 22 (1)
      • ►  Apr 16 (1)
    • ►  March (1)
      • ►  Mar 30 (1)
    • ►  January (5)
      • ►  Jan 08 (3)
      • ►  Jan 01 (2)
  • ►  2009 (110)
    • ►  December (8)
      • ►  Dec 18 (2)
      • ►  Dec 05 (1)
      • ►  Dec 04 (5)
    • ►  November (1)
      • ►  Nov 27 (1)
    • ►  October (14)
      • ►  Oct 09 (4)
      • ►  Oct 07 (1)
      • ►  Oct 06 (3)
      • ►  Oct 05 (3)
      • ►  Oct 01 (3)
    • ►  September (17)
      • ►  Sep 30 (1)
      • ►  Sep 29 (1)
      • ►  Sep 28 (1)
      • ►  Sep 25 (1)
      • ►  Sep 24 (1)
      • ►  Sep 17 (2)
      • ►  Sep 15 (3)
      • ►  Sep 11 (2)
      • ►  Sep 09 (3)
      • ►  Sep 08 (2)
    • ►  August (31)
      • ►  Aug 31 (1)
      • ►  Aug 27 (3)
      • ►  Aug 26 (1)
      • ►  Aug 25 (2)
      • ►  Aug 24 (1)
      • ►  Aug 22 (2)
      • ►  Aug 21 (3)
      • ►  Aug 20 (2)
      • ►  Aug 19 (3)
      • ►  Aug 18 (1)
      • ►  Aug 16 (1)
      • ►  Aug 12 (2)
      • ►  Aug 11 (1)
      • ►  Aug 10 (3)
      • ►  Aug 07 (4)
      • ►  Aug 06 (1)
    • ►  July (24)
      • ►  Jul 25 (4)
      • ►  Jul 24 (20)
    • ►  April (15)
      • ►  Apr 10 (3)
      • ►  Apr 07 (9)
      • ►  Apr 06 (3)

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments
copyright @ TechGiant 2015. Powered by Blogger.

Disclaimer

This is my personal blog and i write articles on .Net, WPF, C#, OOPS, Threading and other .Net technologies. This is not related to any of my employer and organizations. This is the result of my personal interest.

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Followers

Copyright © A Developer Journey who codes for fun | Powered by Blogger
Design by Hardeep Asrani | Blogger Theme by NewBloggerThemes.com