# Bad\_alloc error while using margin effect in Segment editor module

**URL:** <https://discourse.slicer.org/t/bad-alloc-error-while-using-margin-effect-in-segment-editor-module/11976>\
**Category:** Support\
**Created:** [June 10, 2020, 7:47am UTC](https://discourse.slicer.org/t/bad-alloc-error-while-using-margin-effect-in-segment-editor-module/11976 "2020-06-10T07:47:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Deepa](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/deepa/32/5634_2.png) [@Deepa](https://discourse.slicer.org/u/Deepa)\
**Post date:** [June 10, 2020, 7:47am UTC](https://discourse.slicer.org/t/bad-alloc-error-while-using-margin-effect-in-segment-editor-module/11976/1 "2020-06-10T07:47:03Z")

</div>

Hello Everyone,

I’ve a 3D volume like [this](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/2X/d/d2474d5bf4d66d4459c50e8a31589bf2670791fb.jpeg).  
For the suggestions offered [here](https://discourse.slicer.org/t/using-crop-volume-module-to-extract-subvolume-from-a-3d-volume/11926/2), I’m trying to use `Scissors` option in `Segment Editor ` to extract a subvolume.

I used the circular option in “Scissors” tab to cut the segment. After obtaining the circular volume, I used the “islands” effect to retain the largest island. Using “Islands” effect on the whole volume worked fine, but I am not sure why memory issues (“bad\_alloc”) occurs for this small volume.

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/6/d62925fb161b3605b1d307cfd79337ed69e403d7.png)

Unable to allocate 705421132 elements of size 4 bytes.

Second try:

> ```
> QXcbConnection: XCB error: 8 (BadMatch), sequence: 24430, resource id: 2622306, major code: 42 (SetInputFocus), minor code: 0
> 10 islands created (566 ignored)
> Unable to allocate 705421132 elements of size 1 bytes.
> 
> ```

```
Traceback (most recent call last):
  File "/folder/Slicer-4.11.0-2020-05-19-linux-amd64/lib/Slicer-4.11/qt-scripted-modules/SegmentEditorEffects/SegmentEditorIslandsEffect.py", line 115, in onApply
    self.splitSegments(minimumSize = minimumSize, maxNumberOfSegments = 1)
  File "/folder/Slicer-4.11.0-2020-05-19-linux-amd64/lib/Slicer-4.11/qt-scripted-modules/SegmentEditorEffects/SegmentEditorIslandsEffect.py", line 223, in splitSe
    self.scriptedEffect.modifySegmentByLabelmap(segmentationNode, segmentID, modifierImage, modificationMode)
MemoryError: std::bad_alloc: std::bad_alloc

```

I’d like to ask for inputs on what can be done to overcome this error

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 10, 2020, 1:17pm UTC](https://discourse.slicer.org/t/bad-alloc-error-while-using-margin-effect-in-segment-editor-module/11976/2 "2020-06-10T13:17:28Z")

</div>

Scissors effect just blanks out voxels, does not crop the volume. If you cannot add a few 10GB physical RAM and you find that configuring more virtual memory (swap space) results in too slow computation then you can reduce your image size before you start segmentation by cropping and/or resampling your input volume using “Crop volume” module.
