DevEncoded attributes segfault if large memory block no longer referenced

Attributes returning DevEncoded data can cause a segfault if the memory they return is released "too early". This is noticeable with large amounts of data (593896 bytes on my system).

The following test fails with a segfault:

def test_read_large_dev_encoded_that_does_not_keep_reference(server_green_mode):

    NUM_BYTES = 593896

    class TestDevice(Device):
        green_mode = server_green_mode

        @attribute(dtype=DevEncoded, access=AttrWriteType.READ)
        def attr(self):
            return "example", bytearray(NUM_BYTES)

    with DeviceTestContext(TestDevice) as proxy:
        encoding, data = proxy.attr
        assert len(data) == NUM_BYTES

If NUM_BYTES is changed to 593895, they pass.

Also, if we keep a reference to the data, they pass:

    class TestDevice(Device):
        green_mode = server_green_mode
        data = b""

        @attribute(dtype=DevEncoded, access=AttrWriteType.READ)
        def attr(self):
            self.data = bytearray(NUM_BYTES)
            return "example", self.data

Possibly related to #147 (closed) (comment).