# Re: Bug segmentation fault

**URL:** <https://www.ruby-forum.com/t/re-bug-segmentation-fault/73873>\
**Category:** Ruby\
**Created:** [October 27, 2006, 6:42pm UTC](https://www.ruby-forum.com/t/re-bug-segmentation-fault/73873 "2006-10-27T18:42:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [October 27, 2006, 6:42pm UTC](https://www.ruby-forum.com/t/re-bug-segmentation-fault/73873/1 "2006-10-27T18:42:02Z")

</div>

From: removed\_email\_address@domain.invalid

> I am trying to display the contents of large array (over 1000 rows)  
> using arrayName.collect {|x| puts x.inspect}  
> However the following occurs:
> 
> [Bug] Segmentation fault  
> ruby 1.8.5 (20006-08-25) [i386-mswin32]

I have no idea if it will make a different, but do you realize that by  
calling collect you are creating an array whose entries are the return  
value of puts (which is always nil). An array of over 1000 nil entries.

I think you probably want either:  
arrayName.each{ |x| puts x.inspect }  
or  
puts arrayName.collect{ |x| x.inspect }

---

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [October 29, 2006, 3:29pm UTC](https://www.ruby-forum.com/t/re-bug-segmentation-fault/73873/2 "2006-10-29T15:29:00Z")

</div>

Gavin K. wrote:

> value of puts (which is always nil). An array of over 1000 nil entries.
> 
> I think you probably want either:  
> arrayName.each{ |x| puts x.inspect }  
> or  
> puts arrayName.collect{ |x| x.inspect }

True, but it shouldn’t segfault in any case. I’m curious what the  
objects of arrayName look like. I was not able to duplicate this  
problem with a 10000 element array of simple objects.

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [October 29, 2006, 3:29pm UTC](https://www.ruby-forum.com/t/re-bug-segmentation-fault/73873/3 "2006-10-29T15:29:00Z")

</div>

Daniel B. wrote:

> > value of puts (which is always nil). An array of over 1000 nil entries.
> > 
> > I think you probably want either:  
> > arrayName.each{ |x| puts x.inspect }  
> > or  
> > puts arrayName.collect{ |x| x.inspect }

This is also a nice alternative to try:

require ‘pp’  
pp arrayName

And, btw, in Ruby we conventionally use underscores instead of camelCase  
so array\_name is preferred. Of course that is a pretty meaningless  
identifier so that should probably named differently altogether. 🙂

> True, but it shouldn’t segfault in any case. I’m curious what the  
> objects of arrayName look like. I was not able to duplicate this  
> problem with a 10000 element array of simple objects.

Yeah, OP what objects do you have in that array? Are you using some  
kind of C extension? Is this a recursive data structure?

Regards

```
robert
```
