• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

Why Go supports Pointers as it can create memory leak issue?

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As we all know that in c language pointer is there and it can create memory leake issue. That why  another programming languages has removes this one.

Now Go Language came with the same support of pointers again. I want to why?

 
Marshal
Posts: 66530
251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What makes you think that pointers create memory leaks? It is incorrect use of pointers and failure to free them that creates such problems.
 
Saloon Keeper
Posts: 10863
234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java doesn't allow the programmer direct access to pointers and you can still create memory leaks.

At any rate, unless the language is fully driven by a stack machine, you need some way to refer to shared memory
 
SunilK Chauhan
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:What makes you think that pointers create memory leaks? It is incorrect use of pointers and failure to free them that creates such problems.



As we all know that java doesn't support pointers and why. Right? That's why I am asking this question.
 
Campbell Ritchie
Marshal
Posts: 66530
251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java® runs on an automated heap, which is why Gosling abandoned pointers. Pointers are good things for some purposes, particularly writing OSs.
 
Stephan van Hulst
Saloon Keeper
Posts: 10863
234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java does have pointers. It just doesn't allow the programmer to operate on them directly. Is that what you mean? Why does Go allow the programmer to operate on pointers directly?

You will have to ask the designers of the language. However, in the official FAQ they explain that one of the design principles was that they wanted the language to be fast, and I imagine that having access to pointers was one way to achieve that.
 
Campbell Ritchie
Marshal
Posts: 66530
251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Java does have pointers. . . . Is that what you mean? . . .

Yes, that is why I meant and didn't write precisely.
 
Sheriff
Posts: 21824
105
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go has pointers, but the difference with pointers in C and C++ is that you don't have to perform the cleanup. Like Java and C#, Go comes with garbage collection. A side effect is that you can do a lot that's not possible in C or C++, like return a pointer to a local variable. In C and C++, that's going to blow up in your face. In Go, it will work just fine.

For instance, I needed pointers to constants. You can do that the hard way, or just simply use a helper function:
 
SunilK Chauhan
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pointers are really a good things that I know. But just a difference that why Java doesn't allow the user to directly use it and why GO allows user to direct access it. That's why I was asking.

Thanks for clarification guys.
 
Everybody's invited. Even this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!