Re: GC question

2017-02-04 Thread osa1 via Digitalmars-d-learn
All GCs are prone to leak, including precise ones. The point of 
garbage collection is not to prevent leaks, but rather to 
prevent use-after-free bugs.


Of course I can have leaks in a GC environment, but having 
non-deterministic leaks is another thing, and I'd rather make 
sure to delete my references to let GC do its thing than to pray 
and hope some random number on my stack won't be in the range of 
my heap.


I don't agree that the point is just preventing use-after-free, 
which can be guaranteed statically even in a non-GC language (see 
e.g. Rust).


Re: GC question

2017-02-04 Thread osa1 via Digitalmars-d-learn

On Saturday, 4 February 2017 at 11:09:21 UTC, thedeemon wrote:

On Wednesday, 1 February 2017 at 06:58:43 UTC, osa1 wrote:

I'm wondering what
are the implications of the fact that current GC is a 
Boehm-style conservative
GC rather than a precise one, I've never worked with a 
conservative GC before.
Are there any disallowed memory operations? Can I break things 
by not following
some unchecked rules etc. ? How often does it leak? Do I need 
to be careful

with some operations to avoid leaks?


Here's some practical perspective from someone who released a 
32-bit video processing app in D with thousands of users.
When developing with GC in D you need to keep in mind 3 key 
things:


1) The GC will treat some random stack data as possible 
pointers, and some of those false pointers will accidentally 
point to some places in the heap, so for any object in GC heap 
there is a probability that GC will think it's alive (used) 
even when it's not, and this probability is directly 
proportional to the size of your object.


2) Each GC iteration scans the whole GC heap, so the larger 
your managed heap, the slower it gets.


Main consequence of 1 and 2: don't store large objects (images, 
big file chunks etc.) in the GC heap, use other allocators for 
them. Leave GC heap just for the small litter. This way you 
practically don't leak and keep GC pauses short.


3) GC will call destructors (aka finalizers) for the objects 
that have them, and during the GC phase no allocations are 
allowed. Also, since you don't know in which order objects are 
collected, accessing other objects from a destructor is a bad 
idea, those objects might be collected already.


Main consequence of 3: don't do silly things in destructor 
(like throwing exceptions or doing other operations that might 
allocate), try avoiding using the destructors at all, if 
possible. They may be used to ensure you release your 
resources, but don't make it the primary and only way to 
release them, since some objects might leak and their 
destructors won't be called at all.


If you follow these principles, your app will be fine, it's not 
hard really.


Honestly this still sounds horrible. I'd be OK with any of these 
two:


- Percise GC, no manual management, no RAII or destructors etc.
- Manual GC, RAII and destructors, smart pointers.

but this:

- Automatic but conservative. Can leak at any time. You have to 
implement manual management (managed heaps) to avoid leaks. Leaks 
are hard to find as any heap value may be causing it.


is the worst of both worlds. I'm surprised that D was able to 
come this far with this.


Re: GC question

2017-02-03 Thread osa1 via Digitalmars-d-learn

On Friday, 3 February 2017 at 10:49:00 UTC, Kagamin wrote:
Leaks are likely in 32-bit processes and unlikely in 64-bit 
processes. See e.g. 
https://issues.dlang.org/show_bug.cgi?id=15723


This looks pretty bad. I think I'll consider something else until 
D's memory management story gets better. This is sad because the 
language otherwise looks quite good, and I'd love to try 
assertions, contracts, scope guards, macros etc.


Re: GC question

2017-02-01 Thread osa1 via Digitalmars-d-learn
On Wednesday, 1 February 2017 at 09:40:17 UTC, Ola Fosheim 
Grøstad wrote:

On Wednesday, 1 February 2017 at 06:58:43 UTC, osa1 wrote:

I'm wondering what
are the implications of the fact that current GC is a 
Boehm-style conservative
GC rather than a precise one, I've never worked with a 
conservative GC before.


The GC isn't competitive with the ones you find in GC languages 
(Java, Go etc). E.g. Go is now aiming for GC pauses in the 
microseconds range.


Resource management in D is rather lacklustre, even C++ does 
better imho. D seems to move towards using thread local 
ref-counting and making GC optional. I guess that would be ok 
on cpus with few cores, but not really adequate on many core 
CPUs.


Thanks for the answer. Could you elaborate on the lacklustre 
part? It's fine if I have to do manual memory management, but I 
don't want any leaks. Ideally I'd have a precise GC + RAII style 
resource management when needed.


GC question

2017-01-31 Thread osa1 via Digitalmars-d-learn

Hi all,

I was looking at D as the next language to use in my hobby 
projects, but the

"conservative GC" part in the language spec
(http://dlang.org/spec/garbage.html) looks a bit concerning. I'm 
wondering what
are the implications of the fact that current GC is a Boehm-style 
conservative
GC rather than a precise one, I've never worked with a 
conservative GC before.
Are there any disallowed memory operations? Can I break things by 
not following
some unchecked rules etc. ? How often does it leak? Do I need to 
be careful
with some operations to avoid leaks? Is a precise GC in the 
roadmap? any kind

of comments on the GC would be really appreciated.

Thanks