I have define the data class as:
data class chatModel(var context:Context?) {
var chatManger:ChatManager?=null
//getter
get() = chat
It is important to remember that referring to chatManger ANYWHERE in the code ends up calling getChatManger() or setChatManger(), including inside of the getter or setter itself. This means your code will end up in an infinite loop and cause a StackOverflowError.
Read up on Properties, specifically the section about getters/setters as well as the "backing field".